MVC Validation Error Messages not hardcoded in Attributes

2.1k views Asked by At

I have a requirement that the validation error messages that are passed to my view come from the database.

I want to use data annotation on my model but the error message key in validation attributes can only be a string or a constant.

I'm open to other solutions for validation but I need to pull the error messages from the database.

Are there any other ellegent solutions for validation were the error message is not a string? Right now I am thinking about using T4 to generate a constants file...

2

There are 2 answers

0
detroitpro On BEST ANSWER
1
Josh Pearce On

You could overload the validation runner to swap out error messages with ones from a database.