For the following:
@Ajax.ActionLink("Delete", "Delete", "AdminGroup", new { id = item.AdminGroupId }, new AjaxOptions { Confirm = "Delete?", HttpMethod = "Delete", OnSuccess = "function() { $(this).parent().parent().remove() }" })
OnSuccess get's errored out. please help. thanks
It should be like this:
@Ajax.ActionLink(
"Delete",
"Delete",
"AdminGroup",
new { id = item.AdminGroupId },
new AjaxOptions {
Confirm = "Delete?",
HttpMethod = "Delete",
OnSuccess = "handleSuccess"
}
)
where you have:
<script type="text/javascript">
function handleSuccess() {
// TODO: handle the success
// be careful because $(this) won't be
// what you think it is in this callback.
}
</script>
Here's an alternative solution I would recommend you:
@Html.ActionLink(
"Delete",
"Delete",
"AdminGroup",
new { id = item.AdminGroupId },
new { id = "delete" }
)
and then in a separate javascript file AJAXify the link:
$(function() {
$('#delete').click(function() {
if (confirm('Delete?')) {
var $link = $(this);
$.ajax({
url: this.href,
type: 'DELETE',
success: function(result) {
$link.parent().parent().remove();
}
});
}
return false;
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With