[英]ASP.NET MVC2 Ajax ActionLink calls wrong action
I am trying to change some data on my page using Ajax. 我正在尝试使用Ajax更改页面上的一些数据。 This is a piece of code that does it: 这是一段实现它的代码:
<%= Ajax.ActionLink("Rate Up", "RatePost", new { postId = post.Id, rating = 1 }, new AjaxOptions { UpdateTargetId = string.Format("postRating_{0}", count) })%>
The problem is that RatePost action is not called after click on this link. 问题是单击此链接后未调用RatePost操作。 Instead, the parent view action is being called. 相反,将调用父视图操作。 How can I avoid this and just call the RatePost action with parameters I specified? 如何避免这种情况,仅使用指定的参数调用RatePost操作?
The code seems to be correct. 该代码似乎是正确的。
Verify that you included the Microsoft Ajax scripts in your view: 验证您是否在视图中包括了Microsoft Ajax脚本 :
<script src="<%= Url.Content("~/Scripts/MicrosoftAjax.js") %>" type="text/javascript">/script>
<script src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.js") %>" type="text/javascript"></script>
If something fails in the javascript generated by Ajax.ActionLink
, the click action is not cancelled. 如果Ajax.ActionLink
生成的javascript失败,则不会取消click动作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.