ASP.NET MVC 2 RTM - Multiple-attribute validation with localization using data annotation fails
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; }
}
I figured it out. The StringLength attribute was wrong. You have to use ErrorMessageResourceName, not ErrorMessage. It should be like this:
[StringLength(50, ErrorMessageResourceType = typeof(ViewRes.Contact), ErrorMessageResourceName = "ValNameLength")]
精彩评论