stringlength 属性错误消息采用哪些参数? [英] What parameters does the stringlength attribute errormessage take?
问题描述
在 MVC4 模板中,使用的数据注释属性之一是 stringlength.
In the MVC4 template one of the data annotation attributes used is stringlength.
例如:
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
哪些参数 {0}、{1}、{2}(更多?)是合法的?
What parameters {0}, {1}, {2} (more?) are legal?
更具体地说,我可以从示例和反复试验中看到可能性是什么,但我希望看到一些硬文档.
To be more specific, I can see from the example and trial and error what the possibilities are, but I would like to see some hard documentation.
我在 StringLengthAttribute 文档中找不到任何关于此的信息.
I can't find anything about this in the StringLengthAttribute documentation.
推荐答案
{0}
索引是属性的显示名称,{1}
是MaximumLength
,{2}
是 MinimumLength
.因此,您的错误消息将被格式化为 Foo 的长度必须至少为 6 个字符."
The {0}
index is the display name of property, {1}
is the MaximumLength
, {2}
is the MinimumLength
. So, your error message will be formate as "The Foo must be at least 6 characters long."
这篇关于stringlength 属性错误消息采用哪些参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!