javascript UnobtrusiveJavaScriptEnabled 键在 .NET 中有什么作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31704703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 14:13:20  来源:igfitidea点击:

What does the UnobtrusiveJavaScriptEnabled key do in .NET?

javascript.netasp.net-mvcweb-config

提问by cloudworks

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

我非常熟悉作为一种模式的不显眼的 Javascript,但我很好奇它对 .NET 框架意味着什么。

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:

我正在作为前端开发人员从事一个项目,该项目在后端使用 .NET。在与开发人员(也管理服务器)合作时,他提到必须将我们的项目的 UnobtrusiveJavaScript 设置为 false。也就是说,项目的 web.config 应该有以下内容:

<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.

我的第一反应是这是不好的做法,但是当我进一步思考时,我意识到我真的不明白为什么 .NET 甚至会在项目级别开始有这样的设置,或者它是否甚至对我们的特定项目。

采纳答案by NightOwl888

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.

Brad Wilson 在他的文章Unobtrusive Client Validation in ASP.NET MVC 3 中解释了该设置的目的。简而言之 - 关闭此设置后,客户端验证将使用 Microsoft javascript 库执行(与在 ASP.NET MVC 1 和 2 中执行的方式相同)。否则(打开设置)客户端验证使用 JQuery 验证执行。

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

因此,换句话说,您的应用程序可能具有依赖于执行验证的 Microsoft JavaScript 库的代码。