开发者

Asp.Net Mvc - Replace Ajax.ActionLink with JQuery

开发者 https://www.devze.com 2022-12-16 16:21 出处:网络
Is there a way to replace the following cod开发者_开发百科e with some JQuery code that use unobtrusive javascript instead of what the MicrosoftAjax library does ?

Is there a way to replace the following cod开发者_开发百科e with some JQuery code that use 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>


Add a link with an Id attribute, then bind the click event to the function that will send the Ajax request.

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

Then with jQuery:

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

精彩评论

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

关注公众号