Think not to use the entire view to confirm the deletion. Use helper and javascript "confirm ()". i.e. visualize the mail form and delete the link with an assistant, so that when the user clicks "delete" they get a confirmation hint js "do you have to delete it?". and on ok, the function "returns true" and causes the form to be submitted for deletion. then the delete action is simply redirected to where it would normally be. I hope you use different deletion actions for different objects that you are trying to delete. if your plan is to have a general delete action, so this is more complicated (and IMO is not recommended).
My removal assistant includes many things, but the removal part looks like this (using snips):
string deleteLink = String.Format(@"<a onclick=""deleteRecord({0})"" href='#'>Delete</a><form id='deleteForm' method='post' action='" + routeRelativePath + "/" + actionPrefix + "Delete/" + model.ID + @"'></form>", model.ID);
.. and he (helper) attaches some js too:
function deleteRecord(recordId) { if(confirm('Are you sure you want to delete this {friendlyModelName}?\nNOTE: There is no Undo.')) { // Perform delete var action = "{routeRelativePath}/{actionPrefix}Delete/" + recordId; // jQuery non-AJAX POST version $("form#deleteForm").submit(); } }
.. you can see that the helper creates a Delete link with all the parameters for the route and identifier, etc. Js just performs the “confirm” function and then sends the tiny element you see created by the helper.
[sorry if the samples are not 100% full - I had to delete a lot of things: for example, helper and attached js have many different modes to support ajax POST, etc.]
source share