如何在 ASP MVC 中提交警报后重定向到另一个页面
How to redirect to another page after submitting an alert in ASP MVC
我正在开发 ASP MVC 5 Web 应用程序。
在我的一个页面中,我试图在发送邮件后将用户重定向到主页,这将在显示 SweetAlert 对话框之后进行。
的确,流程必须是这样的顺序:
- Click on Button Confirm
- Showing alert dialog which contains Ok button
- Click on Ok in this dialog
- Close the alert dialog
- Redirecting the user to Home page
问题是在为我工作的过程中,错误的方式如下:
- Click on Button Confirm
- Redirecting the user to Home page
这是我的观点:
<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>
您可以使用 promises
swal("Good job!", "Your order has been confirmed with success :)", "success").then((value) => {
window.location = "/Home/Index";
});
您希望用户单击确定按钮然后执行重定向;
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";
}
});
我正在开发 ASP MVC 5 Web 应用程序。
在我的一个页面中,我试图在发送邮件后将用户重定向到主页,这将在显示 SweetAlert 对话框之后进行。
的确,流程必须是这样的顺序:
- Click on Button Confirm
- Showing alert dialog which contains Ok button
- Click on Ok in this dialog
- Close the alert dialog
- Redirecting the user to Home page
问题是在为我工作的过程中,错误的方式如下:
- Click on Button Confirm
- Redirecting the user to Home page
这是我的观点:
<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>
您可以使用 promises
swal("Good job!", "Your order has been confirmed with success :)", "success").then((value) => {
window.location = "/Home/Index";
});
您希望用户单击确定按钮然后执行重定向;
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";
}
});