Asp.net mvc 重定向后未显示验证消息(使用ModelStateToTempData属性)
我有一个问题,验证消息在重定向后不显示,即使Im使用MVCConrib的。我是否忽略了一些基本的东西Asp.net mvc 重定向后未显示验证消息(使用ModelStateToTempData属性),asp.net-mvc,mvccontrib,Asp.net Mvc,Mvccontrib,我有一个问题,验证消息在重定向后不显示,即使Im使用MVCConrib的。我是否忽略了一些基本的东西 [ModelStateToTempData] public class AccountController : BaseController { public ActionResult LogOn(string email, string password, string returnUrl) { if (!ValidateLogOn(email, passwor
[ModelStateToTempData]
public class AccountController : BaseController
{
public ActionResult LogOn(string email, string password, string returnUrl)
{
if (!ValidateLogOn(email, password))
{
return RedirectToAction("Index", "AnotherController");
}
//other stuff
}
private bool ValidateLogOn(string email, string password)
{
if (!_userTask.ValidateUser(email, password))
{
ModelState.AddModelError("message", "The email or password provided is incorrect.");
}
return ModelState.IsValid;
}
}
视图:
电子邮件
是否在视图中显示验证消息?是否在视图中显示验证消息?是否使用[ModelStateToTempData]装饰两个控制器
James您是否用[ModelStateToTempData]装饰两个控制器
James如果ModelState中有任何错误,则不应重定向到任何其他控制器。如果ModelState中有错误,就没有办法导航到其他控制器——最好在成功时重定向,而不是在失败时重定向 只需检查ModelState是否包含任何错误,并返回您从中收到请求的视图
if (!ValidateLogOn(email, password))
{
return View("Index");
}
如果ModelState中有任何错误,则不应重定向到任何其他控制器。如果ModelState中有错误,就没有办法导航到其他控制器——最好在成功时重定向,而不是在失败时重定向 只需检查ModelState是否包含任何错误,并返回您从中收到请求的视图
if (!ValidateLogOn(email, password))
{
return View("Index");
}