ASP.NET MVC 2,验证,本地化,参数列表可能吗?
我想本地化错误用户输入的错误消息。
例如分钟。城市名称的长度为 2 个字符。
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Validation))]
[StringLength(50, ErrorMessageResourceName = "Max", ErrorMessageResourceType = typeof(Validation))]
[RegularExpression(".{2,}", ErrorMessageResourceName = "Min", ErrorMessageResourceType = typeof(Validation))]
public string City { get; set; }
错误资源字符串当前如下所示:“字符不足。”
现在我想添加更具体的错误消息,例如“至少需要 2 个字符”。
但是,如何使用 ErrorMessageResourceName
和例如 String.Format()
将参数传递给本地化资源字符串,例如“需要最少 {0} 个字符”?
谢谢你!
I want to localize the error message for wrong user inputs.
E.g. min. length of City name is 2 chars.
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Validation))]
[StringLength(50, ErrorMessageResourceName = "Max", ErrorMessageResourceType = typeof(Validation))]
[RegularExpression(".{2,}", ErrorMessageResourceName = "Min", ErrorMessageResourceType = typeof(Validation))]
public string City { get; set; }
The error resource string currently looks like: "Not enough characters."
Now I want to add a more specific error message e.g. "Minimum 2 characters required".
But how can I pass in an argument to a localized resource string like "Minimum {0} characters required" by using ErrorMessageResourceName
and e.g. String.Format()
?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
全球化 ASP.NET MVC 客户端验证
http://haacked.com/archive/2010/05/ 10/globalizing-mvc-validation.aspx
另请参阅 Phil 在该帖子中链接的其他两篇帖子。
Globalizing ASP.NET MVC Client Validation
http://haacked.com/archive/2010/05/10/globalizing-mvc-validation.aspx
Also look at the other two posts Phil has linked in that post.