I've got an inbound view model list, that has basically got four properties in.
public class Complaint
{
public int Id { get; set;}
public string Comments { get; set; }
public int RuleId { get; set; }
public int ResponseId { get; set; }
}
The data is coming through fine, and i can see it be bound to my List controller item.
Depending upon the data contained within RuleId, makes ResponseId and Comments have different validaton requirements. I'm looking to use ModelState.AddModelError to achieve this. In the past when I've had to do this form of validation, I had fixed field names on my View. But this application, I could have 6 groups, I could have 20. AddModelError takes the property name to associate the error with, as I mentioned I have a variable number of items in my list.
Does anyone know how I can loop over my List and know that the item I am inspecting, relates to a specific form field within my View?
foreach(var complaint in List<Complaint>)
{
if (complaint.RuleId == 1) && (complaint.Comments == null)
{
ModelState.AddModelError("INDIVIDUAL PROPERTY NAME NEEDED", "error message");
}
}
Thanks in advance
Tony