我要求传递到我的视图的验证错误消息来自数据库。
我想在我的模型上使用数据注释,但验证属性中的错误消息键只能是字符串或常量。
我愿意接受其他验证解决方案,但我需要从数据库中提取错误消息。
如果错误消息不是字符串,是否还有其他有效的验证解决方案?现在我正在考虑使用 T4 生成常量文件......
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)
我的具体问题可以通过使用 ASP.NET MVC2 元数据和模型验证提供程序来解决。
以下是让我开始的文章:
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
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
您可以使验证运行程序过载,以将错误消息与数据库中的错误消息交换。
You could overload the validation runner to swap out error messages with ones from a database.