15

I am quite familiar with unobtrusive Javascript as a pattern, but I am curious what it means to the .NET framework.

I am working on a project as a front-end developer that uses .NET on the back end. While working with a developer (who also manages the server), he mentioned that UnobtrusiveJavaScript must be set to false for our project. That is, the project's web.config should have the following:

<appSettings>
  ...
  <add key="UnobtrusiveJavaScriptEnabled" value="false" />
</appSettings>

My first reaction was that this was bad practice, but when I though about it further, I realized that I don't really understand why .NET would even have such a setting at the project level to begin with, or whether it even matters for our particular project.

cloudworks
  • 599
  • 1
  • 3
  • 18
  • Look at this answer http://stackoverflow.com/questions/5208247/why-unobtrusivejavascriptenabled-true-disable-my-ajax-to-work – Dean.DePue Jul 29 '15 at 15:32
  • did the developer mention why it should be set to false? – JamieD77 Jul 29 '15 at 16:17
  • @JamieD77 not explicitly, but there are legacy applications on the server, and shared resources on the back end. I presume that the front ends from these other applications require `UnobtrusiveJavaScriptEnabled` to be set to `false` for them to work, and the other developer is asking for the new project to be set up in the same way so they may coexist. – cloudworks Jul 29 '15 at 16:34
  • 1
    from my experience this setting has only prevented functionality and not enabled functionality. If you don't plan on using things like `@Ajax.BeginForm` or `@Ajax.ActionLink`, which can be implemented using standard `$.ajax`, then I wouldn't worry too much about it. – JamieD77 Jul 29 '15 at 16:38
  • @JamieD77 so would you say that the setting *enables* unobtrusive js functionality as opposed to *changing* how js is handled? That is, if we were to use `@Ajax.ActionLink` in the new project and change the setting from `false` to `true`, would you expect it to cause an issue for a legacy app which was *not* using such functionality, or presumed it to be `false`? Obviously testing and code review would be required to confirm. – cloudworks Jul 29 '15 at 17:09
  • 1
    being that it's in the project config i'd say that it wouldn't cause issues for other projects. I'm also pretty sure that it defaults to false. you can also enable the feature on a controller by controller basis http://bradwilson.typepad.com/blog/2010/10/mvc3-unobtrusive-validation.html – JamieD77 Jul 29 '15 at 17:49

1 Answers1

13

From here:

The purpose of that setting is explained by Brad Wilson in his post Unobtrusive Client Validation in ASP.NET MVC 3. Putting it short - with this setting turned off client side validation is being performed using Microsoft javascript libraries (the same way it was performed in ASP.NET MVC 1 and 2). Otherwise (with setting turned on) client side validation is performed using JQuery Validate.

So in other words, your application probably has code that depends on the Microsoft JavaScript libraries that perform validation.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
  • Hi! Is this app setting still required on MVC5 projects? – Ciaran Gallagher Mar 07 '19 at 16:17
  • 1
    The setting is only required if you have some legacy dependency on the old Microsoft JavaScript libraries. If the setting is not explicitly set, the default value is `true`, indicating to use the (modern) JQuery Validate libraries. For a new project, you would never need to touch this setting. – NightOwl888 Mar 07 '19 at 16:35