Currently I’m setting up my domain model to use DataAnnotation validation attributes, like the RequiredAttribute and RangeAttribute.
For one property it looks like this:
[Required(ErrorMessageResourceType = typeof(ModelValidationMessages), ErrorMessageResourceName = "SurnameRequiredMessage")]
public string Surname { get; set; }
However this isn’t the only property, let alone the only model class. The validation messages, however, are only listed only in the ErrorMessageResourceType resource class for the entire assembly.
Questions:
- Is it possible to define the ErrorMessageResourceType property for an entire class?
- Is it possible to define the ErrorMessageResourceType property for an entire assembly?
- If not, any other way?
Thanks in advance!
You could write a custom
DataAnnotationsModelValidator:and then in Application_Start you need to register an adapter for each attribute you use: