I have a view model as shown below
public class SampleViewModel
{
public Model1 Property1 { get; set; }
}
public class Model1
{
[Required]
public string Name{get; set;}
}
In View We have
@Html.DisplayFor(m=>m.Model1.Name)
@Html.ValidationMessageFor(m=>m.Model1.Name)
In Controller we have
public ActionResult Index()
{
Model1 a= new Model1();
SampleViewModel s= new SampleViewModel();
s.Property1=a;
return View(s);
}
When Name is null ModelState is not getting populated with model errors even though I have Required attribute for Name. Where am I doing wrong?