I have a @Ajax.ActionLink which calls a Delete Action. Now I want to use JQuery UI Dialog confirm instead the regular “Confirm” attribute of the Ajax link.
I hook the event to the Ajax.ActionLink using the unobtrusive javaScript. But the action gets submitted and the e.preventDefault(); throughs an error. Can anyone tell me why this happens?
Here is my jQuery code:
$("[data-dialog-confirm]").click(function (e) {
e.preventDefault();
var theHREF = $(this).attr("href");
$("#dialog-confirm").dialog('option', 'buttons', {
"Delete this item": function () {
window.location.href = theHREF;
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
});
$("#dialog-confirm").dialog("open");
});
Here is my MVC code:
@Ajax.ActionLink("Delete", "DeleteConfirmed", new { id = item.Id },
new AjaxOptions
{
HttpMethod = "POST",
OnSuccess = "refreshList"
},
new {data_dialog_confirm="true" }
)
I ended up doing this:
Change the
Ajax.ActionLinktoHtml.ActionLinkand in my JavaScript code I call$.get(theHREF, null, function () { refreshList() });Here is the code:
Here is the MVC 3 ActionLink