I need to disable client-side validation for a form on a single view.
How do I do this?
I do not want to just disable the following JS files:
<script src="@Url.Content("~/Scripts/jquery/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
Client-side validation is executed by the client and can be easily bypassed. Client-side validation is a major design problem when it appears in web applications. It places trust in the browser, an entity that should never be trusted.
To disable validation in a specific controlSet the control's CausesValidation property to false.
To disable validation when clicking a button, set the MVC Button. CausesValidation property value to false.
Server-side validation is slower than client-side input validation. However, server-side input validation is more reliable than client-side input validation. Thus, it's safe to say that client-side data validation improves user experience while server-side input validation improves security.
Brad Wilson describes this in his blog post: http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html - I have highlighted the bits that answers your question (the last line) in the following quote from the blog post:
To turn unobtrusive JavaScript mode on/off and enable/disable client validation by default for the entire application, you can use Web.config:
<configuration> <appSettings> <add key="ClientValidationEnabled" value="true"/> <add key="UnobtrusiveJavaScriptEnabled" value="true"/> </appSettings> </configuration>
You can also turn them on or off with code:
HtmlHelper.ClientValidationEnabled = true; HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
Using code to turn these features on or off actually behaves contextually. If those lines of code are present in your Global.asax file, then it turns unobtrusive JavaScript and client validation on or off for the whole application. If they appear within your controller or view, on the other hand, it will turn the features on or off for the current action only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With