代码之家  ›  专栏  ›  技术社区  ›  Exact

如何在ASP MVC中提交警报后重定向到其他页面

  •  2
  • Exact  · 技术社区  · 7 年前

    我正在开发一个ASP MVC 5 web应用程序。

    在我的一个页面中,我试图在发送邮件后将用户重定向到主页,这将在显示SweetAlert对话框后进行。

    事实上,过程必须按以下顺序进行:

    1. 单击按钮确认
    2. 显示包含“确定”按钮的警报对话框
    3. 在此对话框中单击“确定”
    4. 关闭警报对话框
    5. 将用户重定向到主页

    问题是,为我工作的过程以以下错误的方式进行:

    1. 单击按钮确认
    2. 将用户重定向到主页

    这是我的观点:

    <input type="submit" value="Confirm" style="margin-left:-270px;" onclick="SendEmail()">
    
    <script>
        var SendEmail = function () {
    
            jQuery.ajax({
                type: "POST",
                url: "/Bestellung/SendMailToUser",
    
    
                success: function (data) {
    
                    swal("Good job!", "Your order has been confirmed with success :)", "success");
                    window.location = "/Home/Index";
                }
    
            })
        }
    
    </script>
    
    2 回复  |  直到 7 年前
        1
  •  3
  •   Emre Kabaoglu    7 年前

    您希望该用户单击“确定”按钮,然后执行重定向;

    swal({
      title: 'Good job!',
      text: "Your order has been confirmed with success :)",
      type: 'success',
      showCloseButton:true
    }).then((result) => {
        if (result.dismiss === 'close') {
            window.location = "/Home/Index";
      }
    });
    
        2
  •  2
  •   Satpal    7 年前

    您可以使用 promises

    swal("Good job!", "Your order has been confirmed with success :)", "success").then((value) => {
        window.location = "/Home/Index";
    });