When I generate an error in the controller and return back the view, the validation summary doesn’t show up. All works fine for errors generated from the view itself. How can we make the summary show up?
Here’s the simplified controller method:
[HttpPost]
public ActionResult EditProfil(Prospect prospect)
{
ModelState.AddModelError(string.Empty, "You have an error");
if (!ModelState.IsValid)
return View("Edit", prospect);
return Json(prospect);
}
And the view looks like this:
@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...
}
edit
the problem is a combination of
and
an empty string is
""which is interperted as a property name, event thought it’s an empty string. Either remove the booleanfalsefrom rendering the summary or passnullto the modelstate bag.