单击“是”按钮后,引导程序模式窗口未立即关闭

时间:2020-04-13 13:54:27

标签: javascript jquery asp.net-mvc bootstrap-modal

我在ASP.NET MVC应用程序中使用了一个引导模式窗口。 此模式窗口已参数化,我可以指定标题和消息文本。

下面是模式窗口MyConfirmModalDialog.cshtml:

<div class="modal fade" id="confirmModalDialog" tabindex="-1" role="dialog" aria-labelledby="modalCenterTitle" aria-hidden="true" 
     style="padding:0px;margin-left:0px;left:42%;min-width:15%">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="modalTitle">Modal title</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" 
                        style="margin-top:-30px">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                Modal body
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal" id="confirmCancel">No</button>
                <button type="button" class="btn btn-primary" id="confirmOk">Yes</button>
            </div>
        </div>
    </div>
</div>

此模式窗口使用剃须刀助手放置在另一个视图中:

@Html.Partial("MyConfirmModalDialog");

然后我按如下所示将其显示给用户:

showConfirmation = function (title, message, success, cancel) {
    var modal = $("#confirmModalDialog");
    modal.find(".modal-title").html(title).end()
         .find(".modal-body").html(message).end()
         .modal({ backdrop: 'static', keyboard: false });

    var fClose = function () {
        modal.modal("hide");
    };

    modal.modal("show");

    $("#confirmOk").unbind().one('click', success).one('click', fClose);
    $("#confirmCancel").unbind().one("click", fClose);
};

function onPerformActions() {
    var title = "Warning";
    var message = "Do you wish to continue?";

    var success = function () {
        performActions();
    };

    var cancel = function () {
        // Do nothing
    };

    showConfirmation(title, message, success, cancel);
}

如果用户单击“是”按钮,则从成功函数中,我调用peformActions方法,如上面的代码所示。在方法performActions下面,基本上是在控制器中执行对动作的ajax异步调用:

function performActions()
{
           $.ajax({
                url: '@Url.Action("DoActions", "MyController", new { area = "MyArea" })',
                type: "POST",                
                async: true,
                success: function (resp) {
                    // Do some things on success       
                },
                error: function () {
                    // Do some things on error
                }
            });
}

我遇到的问题是,当用户单击“是”按钮时,模式窗口没有立即关闭,这需要花费几秒钟,然后此模式窗口与过程中随后显示的下一个模式窗口重叠。 / p>

0 个答案:

没有答案