我右边有一个带删除按钮的表。单击这些按钮后,我有一个ajax调用。在OnComplete事件中,我有这段代码:
function JsonDelete_OnComplete(data) {
var json = $.parseJSON(data.responseText);
if (json.Success) {
$(this).parents("tr.item").remove();
}
}
该事件被解雇。我尝试删除已删除的行但它不起作用。你能帮助我吗?我确定问题出现在$(this).... line
上我的表格格式如下:
<table>
<tr class="item">
<td>
@Html.DisplayFor(m => person.FirstName)
</td>
<td>
@Html.DisplayFor(m => person.LastName)
</td>
<td align="right">
@Ajax.ActionLink("delete", "JsonDelete", "People", new { Id = person.Id }, new AjaxOptions { Confirm = "Are you sure you want to Delete this Person? This action cannot be undone.", HttpMethod = "Delete", OnComplete = "JsonDelete_OnComplete" })
</td>
</tr>
</table>
感谢。
答案 0 :(得分:1)
你应该试试,
@Ajax.ActionLink("delete", "JsonDelete", "People", new { Id = person.Id }, new AjaxOptions { Confirm = "Are you sure you want to Delete this Person? This action cannot be undone.", HttpMethod = "Delete", OnComplete = "JsonDelete_OnComplete(data,this)" })
function JsonDelete_OnComplete(data,element) {
var json = $.parseJSON(data.responseText);
if (json.Success) {
$(element).parents("tr.item").remove();
}
}