1
我的主页上有一个登录表单。它的工作原理 - 但如果pw错误,我想显示一条错误消息。我的代码如下。我如何返回到同一页面,但在索引方法中检索模型状态错误?MVC4在首页登录时显示模型状态错误信息登录
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult HomeLogin(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return RedirectToAction("Index");
}
事情是我不认为索引方法知道有一个错误bc我正在使用返回RedirectToAction(“索引”)。 – nerdperson
谢谢!很棒。希望在三个月内我会得到MVC的处理... – nerdperson