2

我正在使用 ASP.Net MVC 来制作我的应用程序

我实际上是在尝试从我的数据库中删除一个条目,首先我必须有一条确认消息,当操作完成时我想刷新我的 PartialView

这是我的代码

          <%= Ajax.ActionLink(
            "Supprimer", 
            "Delete", 
            "Users",
            new { item.ID },
            new AjaxOptions {
              Confirm= "confirmMethod",
              UpdateTargetId = "usersListeID",
              OnSuccess = "success"
           }
              )%>

问题是确认选项是一个简单的 ajax 消息,我想使用我自己的消息(结构良好,因为我使用 ajax 和 jQuery 来制作它)

function confirmMethod() {
$.msgBox({
    title: "Demande de confirmation",
    content: "Voulez-vous effectuer cette action?",
    type: "confirm",
    buttons: [{ value: "Oui" }, { value: "Non"}],
    success: function (result) {
        if (result == "Non") {
            abort();
        }
    }
});}
4

1 回答 1

0

您可以使用标准Html.ActionLink

<%= Ajax.ActionLink(
    "Supprimer", 
    "Delete", 
    "Users",
    new { item.ID },
    new { @class = "delete" }
) %>

然后使用jQuery订阅.click()tis锚的事件:

$(function() {
    $('.delete').click(function() {
        var anchor = this;
        // Show the confirmation dialog
        $.msgBox({
            title: "Demande de confirmation",
            content: "Voulez-vous effectuer cette action?",
            type: "confirm",
            buttons: [{ value: "Oui" }, { value: "Non"}],
            success: function (result) {
                if (result == "Oui") {
                    // send the AJAX request if the user selected "Oui":
                    $.ajax({
                        url: anchor.href,
                        type: 'POST',
                        success: function(data) {
                            // When the AJAX request succeeds update the 
                            // corresponding element in your DOM
                            $('#usersListeID').html(data);
                        }
                    });
                }
            }
        });

        // Always cancel the default action of the link
        return false;
    });
});
于 2013-01-28T07:46:30.803 回答