In my application, I'm using the dataAnotation as below for validating my ViewModels:
[DisplayName("Provider Business Name") ]
[StringLength(35)]
public string ProviderBusinessName
{
get { return _providerBusinessName; }
set { _providerBusinessName = value.ToUpper(); }
}
My environment is Asp.Net Webforms 4.0 and I'm manually invoking the validation with the following code:
dynamic context = new ValidationContext(datamodel, serviceProvider: null, items: null);
results = new List<ValidationResult>();
return Validator.TryValidateObject(datamodel, context,
results, validateAllProperties: true);
My problem is that the error messages are using the property name instead of the contents of the DisplayName attribute. As far as I can see, the validation attributes should use the DisplayName in the error message.