2

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

detroitpro
  • 3,853
  • 4
  • 35
  • 64

2 Answers2

3

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
  • 3,853
  • 4
  • 35
  • 64
1

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

Josh Pearce
  • 3,399
  • 1
  • 23
  • 24
  • 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 Nov 24 '09 at 04:55