我无法将其添加为注释,但您需要在POST版本的
Register
行动
[AllowAnonymous]
[HttpPost]
public ActionResult Register(RegisterViewModel model) {
if (!ModelState.IsValid) {
model.Initalize();
ModelState.AddModelError(string.Empty, "");
return View("Register", model);
}
if (ModelState.IsValid && model.Register != null) {
if (RegisterViewModel.RegisterNewUser(model.Register))
return RedirectToAction("RegisterSuccess");
else
{
ModelState.AddModelError("", NMPAccountResource.Failed);
//there needs to be code here to return the view.
return View("Register", model); //<--- this is missing
}
}
//there needs to be code here to return the view.
return View("Register", model); //<--- this is missing
}
如果出现以下情况,您的代码可能以前一直在工作
!ModelState.IsValid
是
符合事实的
。可能您尚未通过此检查,下面的代码在运行时失败。