开发者

ASP.NET MVC2 Ajax ActionLink calls wrong action

开发者 https://www.devze.com 2023-01-31 19:02 出处:网络
I am trying to change some data on my page using Ajax. This is a piece of code that does it: <%= Ajax.ActionLink(\"Rate Up\", \"RatePost\", new { postId = post.Id, rating = 1 }, new AjaxOptions {

I am trying to change some data on my page using 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 actio开发者_如何学Gon is not called after click on this link. Instead, the parent view action is being called. How can I avoid this and just call the RatePost action with parameters I specified?


The code seems to be correct.

Verify that you included the Microsoft Ajax scripts in your view:

<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.

0

精彩评论

暂无评论...
验证码 换一张
取 消