I have the following models:
class Identity
{
public string Name { get; set; }
public string Surname { get; set; }
}
class Person
{
public Identity Identity { get; set; }
}
Now I want to add a validation model error to the surname in my controller:
[HttpPost]
public ActionResult CreatePerson(Person person)
{
// some validation stuff
ModelState.AddModelError("Identity.Surname", "Surname has not been found in BBDD");
^^^^^^^^^^^^^^^^
}
How must I refer to the surname inside the Identity
object to show the validation error correctly in my view?
I show the validation error in the view as:
@Html.ValidationMessageFor(model => model.Identity.Surname)
But the error is shown in the general validation summary.