是否可以在重定向到新 View 之前在 Controller 中创建警报提示?我想让用户在将他们定向到下一个 View 之前确认当前 View 中的消息
using System.Web.Mvc;
using System.Web.Security;
using MvcApplication.Models;
[HttpPost]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (!this.ModelState.IsValid)
{
return this.View(model);
}
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
***// Here! create an alert with a close button using javascript and make the user acknowledge it by clicking a button and closing the alert before redirecting the user***
if (this.Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return this.Redirect(returnUrl);
}
return this.RedirectToAction("Index", "Home");
}
this.ModelState.AddModelError(string.Empty, "The user name or password provided is incorrect.");
return this.View(model);
}
最佳答案
从该方法返回一些包含消息、链接和/或自动重定向的 View 。
“暂停” Controller 的处理以将消息发送回用户是不可能的!!
关于javascript - 如何在重定向到新 View 之前在 Controller 中创建警报提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43269401/