I have a class :
public class Cust
{
[Required(ErrorMessage ="NameField Req")]
public string Name { get; set; }
}
I use this class :
public class CustModel
{
public IEnumerable<Cust> CustList { get; set; }
}
.Cshtml
@model WebApplication2.Models.CustModel
@Html.EditorFor(m => m.CustList)
@Html.ValidationMessageFor(val => val.CustList)
When I hit on Submit button if (ModelState.IsValid){} is working but why my error message is not displayed ?
I managed to re-produce your code, assuming your view:
Please, pay attention to the for loop:
according to the following actions in the Controller:
The code above, is tested, built and run successfully.
Hope this helped ... :)