当我在控制器中生成错误并返回视图时,验证摘要不会显示。对于视图本身生成的错误,一切正常。我们怎样才能使摘要显示出来?
这是简化的控制器方法:
[HttpPost]
public ActionResult EditProfil(Prospect prospect)
{
ModelState.AddModelError(string.Empty, "You have an error");
if (!ModelState.IsValid)
return View("Edit", prospect);
return Json(prospect);
}
视图如下所示:
@model Prospect
@{
ViewBag.Title = "Profil du prospect";
Layout = null;
}
//Some javascript and CSS unrelated to validations
@using (Html.BeginForm())
{
@Html.ValidationSummary(false)
//My form controls...
}