Disable client-side validation in MVC 3 "cancel" submit button
What is this mystical force that causes the answer to reveal itself as soon as you post a question somewhere?
It looks like in MVC 3 you disable client-side validation on a button by adding the class "cancel" to it. So in my example:
<input type="submit" name="backButton" value="← Back"
title="Go back to step 1." class="cancel" />
works great. And no ID attribute is needed either. If you have an actual style class on the button, just do this:
<input type="submit" name="backButton" value="← Back"
title="Go back to step 1." class="style-name cancel" />
I know... very old question.. Yet it was the top of the search results when I looked.
For MVC 4 (and a BUTTON) it seems (at least for me) that the answer is simply adding the formnovalidate="formnovalidate"
<button type="submit" class="btn btn-outline-success border-0" formnovalidate="formnovalidate" name="command" value="Back" title="Back">
<span class="fas fa-arrow-left" aria-hidden="true"></span>
Back
</button>
The validation scripts seem to be linked to the submit type input
. By changing cancel
to a button, validation is skipped:
<button type="button" onclick="document.location.href('Index')">Cancel</button>