Exact
Exact

Reputation: 269

How to redirect to another page after submitting an alert in ASP MVC

I am developing an ASP MVC 5 web application.

In one of my page, I am trying to redirect the user to the home page after sending mail and this will be after showing a SweetAlert Dialog.

Indeed, the process must be in this order:

  1. Click on Button Confirm
  2. Showing alert dialog which contains Ok button
  3. Click on Ok in this dialog
  4. Close the alert dialog
  5. Redirecting the user to Home page

The problem is that the process in working for me in this following wrong way:

  1. Click on Button Confirm
  2. Redirecting the user to Home page

This is my view :

<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>

Upvotes: 2

Views: 3582

Answers (2)

Emre Kabaoglu
Emre Kabaoglu

Reputation: 13146

You want that user clicks the ok button and performing redirection then;

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";
  }
});

Upvotes: 3

Satpal
Satpal

Reputation: 133403

You can use promises

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

Upvotes: 2

Related Questions