Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 981
Mediator Avatar asked Nov 07 '12 21:11

Mediator


People also ask

Can client-side validation be bypassed?

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.

How can you bypass the validation of ASP.NET control?

To disable validation in a specific controlSet the control's CausesValidation property to false.

How can disable validation on button click in ASP.NET MVC?

To disable validation when clicking a button, set the MVC Button. CausesValidation property value to false.

Why server side validation is better than client-side validation?

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.


1 Answers

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.

like image 84
Lasse Christiansen Avatar answered Nov 15 '22 05:11

Lasse Christiansen