ASP.NET MVC 3 and jquery.unobtrusive-ajax.min.js

一曲冷凌霜 提交于 2019-11-29 10:46:56

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 is jQuery and jquery.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>

This is an old post, but if anyone needs the latest on unobtrusive ajax, it can be found here:

http://nuget.org/packages/Microsoft.jQuery.Unobtrusive.Ajax/3.0.0-beta2

There are other stable versions that work on latest jquery lib.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!