Javascript 从 ASP.NET MVC 3 开始,MicrosoftAjax.js、MicrosoftMvcAjax.js 和 MicrosoftMvcValidation.js 是否已过时?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8782697/
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
Are MicrosoftAjax.js, MicrosoftMvcAjax.js and MicrosoftMvcValidation.js obsolete as of ASP.NET MVC 3?
提问by Jake Petroules
Are MicrosoftAjax.js
, MicrosoftMvcAjax.js
and MicrosoftMvcValidation.js
obsolete as of ASP.NET MVC 3? I haven't been able to find much info on this on the web, but from what I've read it implies that these files were used in ASP.NET MVC 1-2, and were replaced by jquery.validate.min.js
, jquery.unobtrusive-ajax.min.js
and jquery.validate.unobtrusive.min.js
. Is that correct? Do I still need the Microsoft files?
是MicrosoftAjax.js
,MicrosoftMvcAjax.js
和MicrosoftMvcValidation.js
过时的ASP.NET MVC 3的?我在网上找不到太多关于此的信息,但从我读到的内容来看,这意味着这些文件在 ASP.NET MVC 1-2 中使用,并被替换为jquery.validate.min.js
,jquery.unobtrusive-ajax.min.js
和jquery.validate.unobtrusive.min.js
. 那是对的吗?我还需要 Microsoft 文件吗?
回答by Darin Dimitrov
Yes, all Microsoft*
helpers are obsolete in ASP.NET MVC 3. For me they have always been obsolete but now at least Microsoft made this official and replaced them with jQuery.
是的,Microsoft*
ASP.NET MVC 3 中的所有帮助程序都已过时。对我而言,它们一直已过时,但现在至少微软正式发布并用 jQuery 替换了它们。
2 new functionalities have been introduced
引入了 2 个新功能
<appSettings>
<add key="webpages:Version" value="1.0.0.0"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
The first is UnobtrusiveJavaScriptEnabled
. This means that if you enable this functionality in your web.config (its enabled by default when you create a new ASP.NET MVC 3 application), all the Ajax.*
helpers such as Ajax.BeginForm
and Ajax.ActionLink
will emit HTML5 data-* attributes on their respective DOM elements instead of mixing javascript with markup. Then you should include the jquery.unobtrusive-ajax.js
script to your page which will parse those attributes and use jQuery to unobtrusively AJAXify them.
第一个是UnobtrusiveJavaScriptEnabled
。这意味着,如果您在 web.config 中启用此功能(在您创建新的 ASP.NET MVC 3 应用程序时默认启用),所有Ajax.*
帮助程序(例如Ajax.BeginForm
和 )Ajax.ActionLink
将在其各自的 DOM 元素上发出 HTML5 data-* 属性将 javascript 与标记混合使用。然后您应该将jquery.unobtrusive-ajax.js
脚本包含到您的页面中,该脚本将解析这些属性并使用 jQuery 以不显眼的方式对它们进行 AJAX 化。
The second is ClientValidationEnabled
which is also enabled by default. The same way unobtrusive javascript works, when you enable this setting all helpers that generate input fields will emit HTML5 data-* attributes on them. Then you include jquery.validate.js
and jquery.validate.unobtrusive.js
scripts to make them work, such as in your _Layout.cshtml. They must appear in this order, and they must be after jquery is loaded:
第二个ClientValidationEnabled
也是默认启用的。与非侵入式 javascript 的工作方式相同,当您启用此设置时,所有生成输入字段的助手都将在其上发出 HTML5 data-* 属性。然后您包含jquery.validate.js
和jquery.validate.unobtrusive.js
脚本以使它们工作,例如在您的 _Layout.cshtml 中。 它们必须按此顺序出现,并且必须在 jquery 加载之后:
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
So in ASp.NET MVC 3 you can forget about all Microsoft*
scripts. Remove them from your site. Delete those files.
因此,在 ASp.NET MVC 3 中,您可以忘记所有Microsoft*
脚本。从您的网站中删除它们。删除那些文件。
回答by LewisBenge
You only need the MicrosoftAjax functionality if you are using the libraries. Microsoft AJAX does offer some functionality not found in the provided JQuery libraries (although could be replicated with plug-ins). If you are not using Microsoft AJAX within your application you can delete all reference to these scripts.
如果您使用这些库,则只需要 MicrosoftAjax 功能。Microsoft AJAX 确实提供了一些在提供的 JQuery 库中没有的功能(尽管可以用插件复制)。如果您的应用程序中没有使用 Microsoft AJAX,则可以删除对这些脚本的所有引用。