即使我使用 MVCConrib 的ModelStateToTempData ,我也遇到了重定向后不显示验证消息的问题。我是否忽略了一些基本的东西?
[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;
}
}
看法:
<li>
<label for="email">E-mail</label>
<%= Html.TextBox("email")%>
<%= Html.ValidationMessage("message") %>
</li>