Mediator
Mediator

Reputation: 15378

How to disable client-side validation for a single view?

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>

Upvotes: 5

Views: 4858

Answers (1)

Lasse Christiansen
Lasse Christiansen

Reputation: 10325

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.

Upvotes: 12

Related Questions