Nebojsa Veron
Nebojsa Veron

Reputation: 1615

ASP.NET MVC2 Ajax ActionLink calls wrong action

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 action 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?

Upvotes: 0

Views: 736

Answers (1)

Daniel Pe&#241;alba
Daniel Pe&#241;alba

Reputation: 31847

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.

Upvotes: 1

Related Questions