数据注解让errormessage的出库 [英] Data-annotation getting errormessage out database
问题描述
使用asp.net mvc的,您可以使用注释
[必填(errormessage的=这是必需的)]
With asp.net mvc you can use the annotation [Required (errormessage="This is required")]
我如何创建这样的:
[必需的(errormessage的=ERRORXX)]
[Required (errormessage="ERRORXX")]
所以我可以查找数据库中的这是什么ERRORXX是和我的表格上显示它。现在我的表单显示ERRORXX。
So I can look up in a database what this ERRORXX is and display it on my form. Now my form displays ERRORXX.
我怎么能创造的东西,解决我的问题?
How can I create something that solves my problem?
THX!
推荐答案
只是一个想法:为什么不从的 RESX文件?我认为这是这样做的常用方法。它甚至可以让你轻松本地化的错误消息。
Just an idea: why not pull the error messages from a resx file? I think this is the common way of doing this. It even allows you to localize your error messages easily.
我觉得用一个资源文件(RESX文件),它更容易改变以后的错误消息。一个RESX文件可以打开并在Word中编辑垫为例。你并不需要访问使用用户名/密码的数据库,查询它,等等。
I think that by using a resource file (resx file) it's even easier to change the error messages later on. A resx file can be opened and edited in Word Pad for example. You don't need to access a database with username/password, query it, etc.
看看这里太:
<一个href=\"http://dotnetslackers.com/articles/aspnet/customizing-asp-net-mvc-2-metadata-and-validation.aspx#s2-validation\"相对=nofollow>自定义ASP.NET MVC 2 - 元数据和验证
这篇关于数据注解让errormessage的出库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!