仅使用 Jquery + Ajax 如何重写此语句?此代码显示一个链接。当我单击它时,视图将返回到 StuffPanel id 中。
@{ AjaxOptions options = new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "StuffPanel",
OnBegin = "OnBeginWork",
OnComplete = "OnCompleteWork",
};}
<p>@Ajax.ActionLink("show stuff", "Index", "Stuff", options)</p>
干得好:
<a href="/Index/Stuff" id="action">show stuff</a>
$(function() {
$('#action').click(function(e) {
e.preventDefault();
var url = $(this).attr('href');
$.ajax({
url: url,
beforeSend: OnBeginWork,
complete: OnCompleteWork,
success: function(html) {
$('#StuffPanel').html(html);
}
});
});
});
我建议您保留 actionLink,因为它所做的只是为您获取正确的路由。为其添加一个 ID,以便您可以更轻松地绑定单击事件,然后使用单击事件回调来触发 ajax 调用。使用 success 函数替换内容#StuffPanel
与回应。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)