[英]ASP.NET Code generated by Ajax.ActionLink stopped working after Upgrading to JQuery 2.0.1
I have an ASP.NET MVC3 app that I have upgrade to JQuery 2.0.1, unfortunately this has had some unpleasant side effects. 我有一个升级到JQuery 2.0.1的ASP.NET MVC3应用程序,不幸的是,这有一些令人不愉快的副作用。 ( More info here ) ( 更多信息在这里 )
Currently I have only one outstanding issue: The HTML link generated by @Ajax.ActionLink no longer calls the appropriate js code, but instead is treated as a regular link by the browser. 当前,我只有一个未解决的问题:@ Ajax.ActionLink生成的HTML链接不再调用相应的js代码,而是被浏览器视为常规链接。
The page in question contains the following js files: 有问题的页面包含以下js文件:
<script src="/Scripts/jquery-2.0.1.min.js" type="text/javascript"></script>
<script src="/Scripts/modernizr-2.6.2.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui-1.10.3.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript">script>
<script src="~/Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"> </script>
I have had to manually update the jquery.unobtrusive-ajax.min.js
file to resolve another issue (replace live
by on
). 我不得不手动更新jquery.unobtrusive-ajax.min.js
文件来解决另一个问题(用on
代替live
)。
The Ajax.ActionLink
looks as follows: Ajax.ActionLink
如下所示:
@Ajax.ActionLink("Delete", "Delete", "InputResources",
new { id = Model[i].ID },
new AjaxOptions
{
HttpMethod = "DELETE",
Confirm = "Are you sure you want to delete?",
OnComplete = "window.location.href='/Projects/InputResources/" + ViewBag.ProjectID + "'"
})
The HTML generated seems to look sound: 生成的HTML看起来不错:
<a href="/InputResources/Delete/5" data-ajax-method="DELETE" data-ajax-confirm="Are you sure you want to delete?" data-ajax-complete="window.location.href='/Projects/InputResources/2'" data-ajax="true">Delete</a>
Can anyone suggest what js files and how I need to modify in order to get this link working correctly again? 谁能建议什么js文件以及我需要如何修改才能使此链接再次正常工作?
Here is what solved it for me: 这是为我解决的问题:
This will update your jquery validation script to latest version: 这会将您的jquery验证脚本更新为最新版本:
PM> Install-Package jQuery.Validation
This will update your jquery unobtrusive validation script to latest version: 这会将您的jquery非侵入式验证脚本更新为最新版本:
PM> Install-Package jQuery.Ajax.Unobtrusive
Make sure both are included in your page after jquery library, it will not work if you don't do this. 确保两者都包含在jquery库之后的页面中,如果不这样做,则将不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.