Reputation: 9332
I have a table with a delete button on the right. When these button are clicked, I have an ajax call. On the OnComplete event, I have this code:
function JsonDelete_OnComplete(data) {
var json = $.parseJSON(data.responseText);
if (json.Success) {
$(this).parents("tr.item").remove();
}
}
The event is fired. I try to remove the deleted line but it doesn't work. Can you help me? I'm sure the problem is on the $(this).... line
My table is formatted as this:
<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>
Thanks.
Upvotes: 0
Views: 258
Reputation: 3952
you should try,
@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();
}
}
Upvotes: 1