views:

286

answers:

3

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...

+1  A: 

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

Josh Pearce
Thanks!, you got me looking in the right spot. I'm going to use the ASP.NET MVC2 Metadata and Model Validation Providers to solve my specific problem.
Detroitpro
+2  A: 

My specific problem can be solved by using the ASP.NET MVC2 Metadata and Model Validation Providers.

Here are the articles that got me started:

http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-2-modelmetadata.html

http://dotnetslackers.com/articles/aspnet/customizing-asp-net-mvc-2-metadata-and-validation.aspx

http://haacked.com/archive/2009/10/01/asp.net-mvc-preview-2-released.aspx

Detroitpro
A: 

Hi Detroitpro, we have the same issue you mentioned above. Could you find an intact solution for that? We are using MVC 1.0 but on the way to 2.0 RC2.

Serdar