I am using the jQuery UI dialog. I have a removal form as follows:
@using (Ajax.BeginForm("DeleteUser", "Administrator", new { id = Model }, new AjaxOptions { OnSuccess = "Deleted", OnBegin = "DeletingUser" }, new { id = "frm" + Model, name = Model })) { <input type="submit" value="" /> }
I want modal confirmation to appear before sending the ajax request, and the user selects yes or no.
Here is my javascript:
<script> function DeletingUser(){ $( "#dialog-confirm" ).dialog({ resizable: false, height:140, modal: true, buttons: { "Delete all items": function() { $( this ).dialog( "close" ); }, Cancel: function() { $( this ).dialog( "close" ); } } }); </script> <div id="dialog-confirm" title="Empty the recycle bin?"> <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p> </div>
As you can see from the javascript code, the dialog opens asynchronously, which leads to the fact that the method returns nothing and the form submitted in any case without the user choosing yes or no. How to fix it?
source share