我有一份文件清单,并为每条记录执行了不同的操作。要删除记录,我需要将id传递给控制器。我使用JQuery来执行删除。在其中我需要记录的Id。以下是我的观点:
<script type="text/javascript">
$(function() {
$(".delete_link").live("click", function(e) {
alert("Hi");
e.preventDefault();
if (confirm("Are you sure you want to delete?")) {
$.post("/BuildDocument/DeleteBuildDocument", {need to pass id here..});
}
else {
$.post("/BuildDocument/IndexBuildDocument");
}
});
});
</script>
<div>
<div>
<h1>
List Build Document</h1>
<ul>
<%if (Model.ToList().Count > 0)
{ %>
<li>
<br />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th align="left">
Part No.
</th>
<th align="left">
Issue No
</th>
<th align="left">
Document template
</th>
<th align="left">
Title
</th>
<th align="center">
View
</th>
<th align="center">
Edit
</th>
<th align="center">
Delete
</th>
</tr>
<% foreach (var item in Model)
{ %>
<tr>
<td>
<%= Html.Encode(item.BldDocPartNo)%>
</td>
<td>
<%= Html.Encode(item.BldDocIssueNo)%>
</td>
<td>
<%= Html.Encode(item.BldDocDocmntTitle)%>
</td>
<td>
<%= Html.Encode(item.BldDocTitle)%>
</td>
<td align="center">
<a href='<%= Url.Action("DetailBuildDocument", "BuildDocument", new { bldDocId = item.BldDocId })%>'>
<img src="../../html/images/edit-icon.gif" alt="edit" border="0" /></a>
</td>
<td align="center">
<a href='<%= Url.Action("EditBuildDocument", "BuildDocument", new { bldDocId = item.BldDocId })%>'>
<img src="../../html/images/Edit.gif" alt="edit" border="0" /></a>
</td>
<td align="center">
<%--<%= Html.ActionLink("Delete", "DeleteBuildDocument", new { bldDocId = item.BldDocId }, new {@class ="delete-link" })%>--%>
<a>
<img src="../../html/images/inst-delete-ico.gif" alt="delete" border="0" /></a>
</td>
</tr>
<% } %>
</table>
</li>
<%} %>
</ul>
</div>
</div>
$.post("/BuildDocument/DeleteBuildDocument", {need to pass id here..});
需要id(BldDocId)。我怎么能得到它?
任何帮助将不胜感激。
答案 0 :(得分:1)
$(".delete_link").live("click", function(e) {
var $link = $(this);
alert("Hi");
e.preventDefault();
if (confirm("Are you sure you want to delete?")) {
$.post("/BuildDocument/DeleteBuildDocument", { var id = $link.attr('bldDocId'); });
}
else {
$.post("/BuildDocument/IndexBuildDocument");
}
});
答案 1 :(得分:1)
我不知道asp.net。 但似乎类名是“delete-link”,来自
new {@class ="delete-link"}
如果我的错误,请不理我。