views:

251

answers:

1

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; }
}
A: 

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

related questions