I have a strongly typed view, which hold controls(input boxes) to represent a collection item. So for an example , take case of a view for adding an Employee detail and within that there are variable set of input fields to enter Department name. These input fields are to be added dynamically at client side.
Here is the class structure of these two entities:
public class Employee
{
public int EmployeeID{get;set;}
public string Name {get;set; }
public IList<Department> DepartmentList{get;set;}
}
public class Deparment {
[Required(ErrorMessage="This is a required Field")]
public string Name {get;set; }
public int ID { get;set; }
}
Inputs for department names are generated dynamically and names are set in a way to achieve model binding after posting
<input type='text' class='input-choice' id='txtChoice0' name='Department[0].Name' />
Now my question is how should I apply validation to this ?. Microsoft Validation won't push the validation inside the mvcClientValidationMetadata , reason for this I assume is that framework doesn't see any model binding happening at the time of view load.
Any ideas ??