加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-3 – MVC3 Ajax.ActionLink

发布时间:2020-12-15 22:30:39 所属栏目:asp.Net 来源:网络整理
导读:对于以下内容: @Ajax.ActionLink("Delete","Delete","AdminGroup",new { id = item.AdminGroupId },new AjaxOptions { Confirm = "Delete?",HttpMethod = "Delete",OnSuccess = "function() { $(this).parent().parent().remove() }" }) OnSuccess得到了错
对于以下内容:
@Ajax.ActionLink("Delete","Delete","AdminGroup",new { id = item.AdminGroupId },new AjaxOptions { Confirm = "Delete?",HttpMethod = "Delete",OnSuccess = "function() { $(this).parent().parent().remove() }" })

OnSuccess得到了错误.请帮忙.
谢谢

解决方法

它应该是这样的:
@Ajax.ActionLink(
    "Delete",new AjaxOptions { 
        Confirm = "Delete?",OnSuccess = "handleSuccess" 
    }
)

你在哪里:

<script type="text/javascript">
function handleSuccess() {
    // TODO: handle the success
    // be careful because $(this) won't be 
    // what you think it is in this callback.
}
</script>

这是我建议你的替代解决方案:

@Html.ActionLink(
    "Delete",new { id = "delete" }
)

然后在一个单独的javascript文件中AJAXify链接:

$(function() {
    $('#delete').click(function() {
        if (confirm('Delete?')) {
            var $link = $(this);
            $.ajax({
                url: this.href,type: 'DELETE',success: function(result) {
                    $link.parent().parent().remove();
                }
            });
        }
        return false;
    });
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读