9

I have the following setting in my web.config:

<appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>

I am not using any client-side validation.

Should I set these to false or is it okay just to delete both entries?

4
  • Possible duplicate? stackoverflow.com/questions/6254213/…
    – Andrew
    Oct 3, 2013 at 16:02
  • leave everything as is. If you don't want to use client-side validation, just don't use any model annotations. But don't go removing and tweaking things for this affect. Oct 3, 2013 at 16:10
  • I checked the link and it says - "I recommend keeping UnobtrusiveJavaScriptEnabled=true because of the lighter ajax attributes it adds." I am even more confused now. Also why should I leave it set these to true if they are actually not true and I don't need them ?
    – user1679941
    Oct 3, 2013 at 18:13
  • 1
    Yes. That's why you should leave BOTH settings to true and use validation on the fields you want validated. Where is the remaining confusion? Oct 15, 2013 at 7:26

4 Answers 4

11
+25

If you don't want it, set it to false. That way you don't even have to guess what the default is later on, and others on the project can see right away that having it turned off was your intention.

Also remove the client validation from the bundleconfig to prevent your users from needless downloads.

1
  • 1
    This is the right answer. If you are not going to use ANY client side validation, turn it off (set EnableCLientSideValidation to false. When this is false, the second item will not be used regardless if it set to true or false). This will prevent the framework from rendering any of the HTML5 attributes or the big ugly <CDATA> section from MVC 1 and 2. See here for more information on the settings: bradwilson.typepad.com/blog/2010/10/…
    – Tommy
    Oct 19, 2013 at 2:24
9

There are 2 different Settings in Web.config that are coupled, but not synonymous.

<add key="ClientValidationEnabled" value="false"/>

Determines whether or not Client Validation is enabled. If the value is set to false, your model annotations (required, min, max, etc) will not create client-side attributes or behaviors.

<add key="UnobtrusiveJavaScriptEnabled" value="true"/>

Determines whether ASP.NET will use JQuery for client side Asynchronous tasks, or raw JavaScript.

If UnobtrusiveJavaScriptEnabled=false, your Client-Side Validation will still work, but will use Raw JavaScript over JQuery.


What is significance of using JQuery over JavaScript?

Some environments choose not to use JQuery. They have heavily customized UI frameworks. JQuery may already be in use in a custom fashion. Or a different JS library may be in use for all Asynchronous enhancement

What are dis-advantages of using raw JavaScript?

  • Your Ajax helpers will not work without JQuery (UnobtrusiveJavaScriptEnabled).

  • Raw JavaScript is messy and fills up your markup with a lot of stuff. JQuery creates lighter and cleaner markup. (The advantage of "lighter ajax attributes")

  • Your raw Javascript will be less robust, and possibly less efficient. Keep in mind, the ASP.NET JavaScript libraries have not evolved in 3 years (long before the release of MVC 3).


In Conclusion:

If you want to disable Client-Side validation, set

<add key="ClientValidationEnabled" value="false"/>

But I recommend you leave ClientValidationEnabled set to true. If you don't decorate your model with validation annotation, the framework won't render validation attributes. Best to leave your options open and decide for each View / ViewModel where to use Client-Side Validation.

I recommend against disabling UnobtrusiveJavaScriptEnabled. There are too many subtle ways JQuery is used by ASP.NET MVC Framework. And this will not disable Client-Side validation.

Important Note: Don't delete either entry. If you want to disable one, just set it to false. By deleting either entry, you leave yourself at the mercy of the Framework's default behavior (which may change over time).

6
  • Dave - just a quick clarification, the UnobtrusiveJavaScriptEnabled setting actually controls how the client side validation is rendered. With this set to true, the HTML5 style attributes are rendered on each form input. With it set to false, the old school JSON blob of <CDATA> text is rendered at the end of the form. While true that the true setting uses jQuery.validate, the false setting will fall back to the old school Microsoft.Ajax.Validate methods and not plain javascript. bradwilson.typepad.com/blog/2010/10/…. Just 2 cents!
    – Tommy
    Oct 19, 2013 at 2:20
  • @Tommy, thanks for the contribution. To clarify, I though the Microsoft.Ajax.Validate library was written in raw Javascript. Is that incorrect? Oct 19, 2013 at 2:36
  • You're probably right, I think it is. The way I read your answer initially made it sound like one was on their own and there was not any framework support :) Anyways, I came across that link when I was looking into the question and though it provided some good info on the attributes in question!
    – Tommy
    Oct 19, 2013 at 4:45
  • @Tommy, I tried to speak to OP's question very specifically; Answering why the UnobtrusiveJavaScriptEnabled flag should be set to true and how that affected lighter ajax attributes OP was so confused about. I'm not sure why my answer is any LESS correct. Oct 19, 2013 at 20:48
  • I know this is old. But, leaving this set to true and "just not using validation attributes" means you have no validation of your <<View>>model server side either.
    – PilotBob
    Jul 30, 2015 at 18:13
2

If you not reference the jquery.validate.unobtrusive.js or delete it from bundles the validation will be disabled. However based on the web.config parameter the @Html helpers generate or not the html attributes used by this script. So I recommend remove the script and set ClientValidationEnabled false.
If you not using the @Ajax helper, the UnobtrusiveJavaScriptEnabled value makes no defference.

2

Unobstrusive settings are Ok.

You need to set ClientValidationEnabled to false.

<configuration>
  <appSettings>
    <add key="ClientValidationEnabled" value="false"/> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/> 
  </appSettings>
</configuration>

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.