In my domain Model I have a Person object that has a number of properties which I have decorated with Validation Metadata:
[Required(ErrorMessage = "First Name Required")]
public string FirstName { get; set; }
[Required(ErrorMessage = "Age Required")]
public int Age { get; set; }
My Controller returns a collection of Persons to the view so that the user can fill in their details. However only the first Person needs to supply an age so I only need to validate the age for the first Person in the collection.
However, due to the Validation metadata on the Age property, the model validation is failing because the age is not being supplied for the other Persons in the collection.
Is there any way to switch off validation for the other Person objects in the collection?
Or do I need to rearrange my Models.