-1

I have an Edit View with a Form which has two submit buttons:

<input type="submit" name="save" value="@Resources.Save" class="btn btn-default" />  
<input type="submit" name="delete" value="@Resources.Delete" class="btn btn-danger" />

Here I can either save the record or delete it.

Then in my controller I do this:

if (Request.Form["delete"] != null)
{
    // delete    
}
else
{
    // edit
}

So everything was working fine untill I added the jQuery Validation plugin and JQuery Validate Unobstrusive (which I needed for a Remote validation).. it broke deletion of records in my application.

My Request.Form["delete"] is now always null. Note that Request.Form does contain all the other values from the Form (and it used to work fine).

Anyone have some ideas how I can solve this issue?

Liiva
  • 278
  • 4
  • 13
  • Please make your question fully self-contained so that it does not require reading the other answer/question for yours to make any sense. Thanks. – Sparky Feb 18 '15 at 17:51
  • 1
    BTW, the jQuery Validate plugin does not change the behavior of the native form submit or the submit buttons, nor can it break your server-side code. It ***only*** stops form submission while the form data remains "invalid" as per your defined rules. Meanwhile, if you really think jQuery Validate could be breaking this, then it would make more sense that you show us the ***relevant*** code... your call to `.validate()` and the HTML of your form, rather than the code that used to work fine. – Sparky Feb 18 '15 at 17:58
  • You never even stated if the validation itself is doing anything. – Sparky Feb 18 '15 at 20:32
  • @Sparky, you bring up some good points but in my defence, all the relevant code **is** shown in my question; after adding the `jquery.validate.js` and `jquery.validate.unobtrusive.js` libraries to my project (I think the latter is causing my issue, I should have been more clear here), the 2 submit buttons acted exactly the same while previously the delete button would submit an additional value compared to the save button. I never make a call to `.validate()`, this is done by the ASP.NET MVC Framework thus there is no code to be shown on that part. – Liiva Feb 19 '15 at 09:02

1 Answers1

0

I managed to solve my issue by adding formnovalidate to my delete button:
<input id="delete" formnovalidate type="submit" name="delete" value="@Resources.Delete" class="btn btn-danger" />

From the Jquery validation reference documentation (here):

Skipping validation on submit

To skip validation while still using a submit-button, add the attribte "formnovalidate" to that input:

1 <input type="submit" name="go" value="Submit">
2 <input type="submit" formnovalidate name="cancel" value="Cancel">

This used to work by adding class="cancel" to the input, this is now deprecated.

So something in either the jquery.validate or jquery.validate.unobtrusive library was preventing my delete value from submitting but I'm not sure what it was..

Community
  • 1
  • 1
Liiva
  • 278
  • 4
  • 13