MVC3 Ajax.ActionLink

前端 未结 1 1796
温柔的废话
温柔的废话 2021-02-03 13:08

For the following:

@Ajax.ActionLink(\"Delete\", \"Delete\", \"AdminGroup\", new { id = item.AdminGroupId }, new AjaxOptions { Confirm = \"Delete?\", HttpMethod =         


        
1条回答
  •  萌比男神i
    2021-02-03 13:55

    It should be like this:

    @Ajax.ActionLink(
        "Delete", 
        "Delete", 
        "AdminGroup", 
        new { id = item.AdminGroupId }, 
        new AjaxOptions { 
            Confirm = "Delete?", 
            HttpMethod = "Delete", 
            OnSuccess = "handleSuccess" 
        }
    )
    

    where you have:

    
    

    Here's an alternative solution I would recommend you:

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

    and then in a separate javascript file AJAXify the link:

    $(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;
        });
    });
    

    0 讨论(0)
提交回复
热议问题