Overriding error messages for all validation attributes

57 Views Asked by At

I'm usingSystem.ComponentModel.DataAnnotations attributes for validation but want to get error messages not from hard-coded strings or resources but from external service. The solution I've found so far requires too much code - create adapter factories for each of the attributes, create a validator provider and replace DataAnnotationsModelValidatorProvider in ModelValidatorProviders.Providers with my own. Is there a better way, some kind of extension point where code could "wrap" all the calls to validation and still has access to attribute itself because I use ErrorMessageResourceType and ErrorMessageResourceName as key to locate proper strings in external service.

(I'm using MVC 5, not ASP.NET Core where this problem looks to be solved)

0

There are 0 best solutions below