开发者

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")]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜