Asp.Net Mvc - Replace Ajax.ActionLink with JQuery

Is there a way to replace the following code with some jQuery code that uses unobtrusive javascript instead of what the MicrosoftAjax library does?

<ul class="vote"> <li> <%= Ajax.ActionLink("Up", "UpVote", new { VoteId = item.Id }, new AjaxOptions() { OnSuccess = "upVote(this)" }, null) %> </li> </ul> 
+4
source share
1 answer

Add a link with an id attribute, and then attach the click event to the function that will send the Ajax request.

 <%= Html.ActionLink("Up","UpVote",new { VoteId = item.Id },new { id = "sendRequest" }) %> 

Then using jQuery:

 $('#sendRequest').click(function() { // $.getJSON or whatever ajax function you want to use }); 
+4
source

All Articles