我的主页上有一个登录表单。它有效 - 但如果密码错误,我想显示错误消息。我的代码如下。如何返回到同一页面但在 Index 方法中检索模型状态错误?
[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");
}