ASP.NET MVC 3和jquery.unobtrusive,ajax.min.js [英] ASP.NET MVC 3 and jquery.unobtrusive-ajax.min.js
问题描述
我想使用的Ajax.ActionLink HTML辅助,因此我需要jquery.unobtrusive-ajax.min.js库,但IE浏览器总是显示此错误:
微软JScript运行时错误:无法设置属性不显眼的值:对象为null或undefined
块引用>我读过的解决方案是jquery.validate.min.js和jquery.validate.unobtrusive.min.js的用法但我不能识别服务器端的Ajax调用。
解决方案
我读过的解决方案是jquery.validate.min.js的使用和
jquery.validate.unobtrusive.min.js
块引用>没有,那些2脚本都无关
jquery.unobtrusive-ajax.min.js
。它们被用于不显眼验证。对于Ajax。*帮手你需要的是的jQuery
和jquery.unobtrusive-ajax.min.js
(包含在< STRONG>该顺序)。因此,对于不显眼的AJAX你需要:
&LT;脚本的src =@ Url.Content(〜/脚本/ jQuery的-1.5.1.min.js)TYPE =文/ JavaScript的&GT;&LT ; / SCRIPT&GT;
&LT;脚本的src =@ Url.Content(〜/脚本/ jquery.unobtrusive-ajax.min.js)TYPE =文/ JavaScript的&GT;&LT; / SCRIPT&GT;如果你想使用不引人注目的验证你也可以包括2个脚本之后(在该顺序排列):
&LT;脚本的src =@ Url.Content(〜/脚本/ jquery.validate.min.js)TYPE =文/ JavaScript的&GT;&LT; /脚本&GT;
&LT;脚本的src =@ Url.Content(〜/脚本/ jquery.validate.unobtrusive.min.js)TYPE =文/ JavaScript的&GT;&LT; / SCRIPT&GT;这是你应该确保另一个非常重要的事情是,你已删除
微软的* .js
从项目脚本绝对任何痕迹。这些脚本已过时,从ASP.NET MVC 3开始不再默认使用。此外,确保启用挥霍在你的web.config不显眼的AJAX,否则系统会退回到传统的Microsoft AJAX脚本:&LT;&的appSettings GT;
&LT;添加键=网页:版本值=1.0.0.0/&GT;
&LT;添加键=ClientValidationEnabledVALUE =真/&GT;
&LT;添加键=UnobtrusiveJavaScriptEnabledVALUE =真/&GT;
&LT; /的appSettings&GT;I want to use the Ajax.ActionLink Html helper therefore I need the jquery.unobtrusive-ajax.min.js library but IE is always showing this error:
Microsoft JScript runtime error: Unable to set value of the property 'unobtrusive': object is null or undefined
I've read that the solution is usage of jquery.validate.min.js and jquery.validate.unobtrusive.min.js but then I can't recognise the ajax call on server side.
解决方案I've read that the solution is usage of jquery.validate.min.js and jquery.validate.unobtrusive.min.js
No, those 2 script have nothing to do with
jquery.unobtrusive-ajax.min.js
. They are used for unobtrusive validation. For Ajax.* helpers all you need isjQuery
andjquery.unobtrusive-ajax.min.js
(included in THAT order).So for unobtrusive AJAX you need:
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
If you want to use unobtrusive validation you could also include the 2 scripts afterwards (in THAT order):
<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>
Another very important thing that you should make sure is that you have removed absolutely any traces of
Microsoft*.js
scripts from your project. Those scripts are obsolete and starting from ASP.NET MVC 3 are no longer used by default. Also make sure that youhave enabled unobtrusive AJAX in your web.config, otherwise the system will fallback to the legacy Microsoft ajax scripts:<appSettings> <add key="webpages:Version" value="1.0.0.0"/> <add key="ClientValidationEnabled" value="true"/> <add key="UnobtrusiveJavaScriptEnabled" value="true"/> </appSettings>
这篇关于ASP.NET MVC 3和jquery.unobtrusive,ajax.min.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!