I\'m using jQuery UI dialog. I have a delete form as follows:
@using (Ajax.BeginForm(\"DeleteUser\", \"Administrator\", new { id = Model }, new AjaxOptions {
A trick. This is my first post, i spend a lot of time to resolve this question, i think that this is easier:
dialog:
function smOpenConfirmDialog(callBack) {
$("#noticeDialog").dialog({
autoOpen: true,
modal: true,
autoOpen: false,
draggable: false,
buttons: {
"Confirm": function () {
callBack();
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
and
$("input:submit").click(function (e) {
smOpenConfirmDialog(function () {
$("form").trigger('submit');
});
e.preventDefault();
});
I think the form is getting submitted because your DeletingUser is not available at post time. see this stackoverflow article (no solution yet)
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 }
))
{
<input type="submit" value="" />
}
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;
});
});