I\'m using jQuery UI dialog. I have a delete form as follows:
@using (Ajax.BeginForm(\"DeleteUser\", \"Administrator\", new { id = Model }, new AjaxOptions {
You could use a normal Html.BeginForm and AJAXify it with jquery. You will have much more control compared to an Ajax.BeginForm helper:
@using (Html.BeginForm(
"DeleteUser",
"Administrator",
new { id = Model },
FormMethod.Post,
new { id = "frm" + Model, name = Model }
))
{
}
and then in a separate javascript file simply:
$(function() {
$('form[id^="frm"]').submit(function() {
var $form = $(this);
$('#dialog-confirm').dialog({
resizable: false,
height:140,
modal: true,
buttons: {
'Delete all items': function() {
$(this).dialog('close');
// the user confirmed => we send an AJAX request to delete
$.ajax({
url: $form.attr('action'),
type: $form.attr('method'),
data: $form.serialize(),
success: function(result) {
Deleted(result);
}
});
},
Cancel: function() {
$(this).dialog('close');
}
}
}
return false;
});
});