简体   繁体   English

Asp.Net Mvc - 用JQuery替换Ajax.ActionLink

[英]Asp.Net Mvc - Replace Ajax.ActionLink with JQuery

Is there a way to replace the following code with some JQuery code that use unobtrusive javascript instead of what the MicrosoftAjax library does ? 有没有办法用一些使用不引人注目的javascript而不是MicrosoftAjax库的JQuery代码替换以下代码?

<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. 添加具有Id属性的链接,然后将click事件绑定到将发送Ajax请求的函数。

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

Then with jQuery: 然后使用jQuery:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM