I have a list of documents and different actions performed for each records. To delete the record i need the id to pass to the controller. I use JQuery to perform deletion. In it I need to Id of the record. The Following is my view:
<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开发者_如何学C 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..});
need the id(BldDocId). How can i get it?
Any help will be appreciated.
$(".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");
}
});
I don't know asp.net. But it seems the class name is "delete-link", from
new {@class ="delete-link"}
If my mistake, ignore me.
精彩评论