ASP.NET MVC 2 RTM - 使用数据注释进行本地化的多属性验证失败
我的资源文件工作正常,并且资源文件中定义了两个键(ValNameRequired 和 ValNameLength)。但是,当您有多个具有本地化的属性时,验证将不起作用。有人有解决办法吗?
public class ContactModel
{
[Required(ErrorMessageResourceType = typeof(ViewRes.Contact), ErrorMessageResourceName = "ValNameRequired")]
[StringLength(50, ErrorMessageResourceType = typeof(ViewRes.Contact), ErrorMessage = "ValNameLength")]
public string Name { get; set; }
}
My resource file is working fine and the two keys (ValNameRequired and ValNameLength) are defined in the resource file. But when you have more than one attribute with localization, then the validation does not work. Anyone with a solution?
public class ContactModel
{
[Required(ErrorMessageResourceType = typeof(ViewRes.Contact), ErrorMessageResourceName = "ValNameRequired")]
[StringLength(50, ErrorMessageResourceType = typeof(ViewRes.Contact), ErrorMessage = "ValNameLength")]
public string Name { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了。 StringLength 属性错误。您必须使用ErrorMessageResourceName,而不是ErrorMessage。应该是这样的:
I figured it out. The StringLength attribute was wrong. You have to use ErrorMessageResourceName, not ErrorMessage. It should be like this: