Hi have this model
public class UserModel
{
[Required(ErrorMessage = "Le nom est requis.")]
[UIHint("String")]
[DataType(DataType.Text)]
[DisplayName("Nom")]
public string Lastname { get; set; }
[DataType(DataType.Text)]
[UIHint("String")]
[DisplayName("Prénom")]
public string Firstname { get; set; }
[Required(ErrorMessage="La spécialité principale est requise.")]
[DisplayName("Spécialité principale")]
public Speciality PrimarySpeciality { get; set; }
[DisplayName("Spécialité secondaire")]
public Speciality SecondarySpeciality { get; set; }
}
public class SpecialityModel
{
[Required(ErrorMessage = "La spécialité est requise.")]
public int Id { get; set; }
public string Name { get; set; }
}
How can the primary Speciality be required and not the second one? It seems that the Required attribute only check for nullable but Speciality is never null.
Edit:
After reading this post http://bradwilson.typepad.com/blog/2010/01/input-validation-vs-model-validation-in-aspnet-mvc.html i'm reformulating my question :How can i prevent sub properties validation to occur before main object. As you can see the SecondarySpeciality is not Required but still get validated cause of the DataAnnotation on the Address class. I'm thinking that mvc2 cannot work with model validation. Should i just go with plain model ? (which means a lot more mapping but if it's work...)