Asp.net-mvc – Using resources with error message in mvc

asp.net-mvcasp.net-mvc-4resources

I want to get error message from resources. When i tried codes below i take that error:"An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type" What can i do ?

public class UserLoginModel
{
     [Required(ErrorMessage =Resources.PageResources.enterYourEmail)]
     public String Email{ get; set; }

     [Required(ErrorMessage =Resources.PageResources.enterPassword)]
     public String Password { get; set; 
}

Best Answer

Try this

 [Required(ErrorMessageResourceType = typeof(Resources.Resources),       
            ErrorMessageResourceName = "enterYourEmail")]
 public String Email{ get; set; }

 [Required(ErrorMessageResourceType = typeof(Resources.Resources),       
            ErrorMessageResourceName = "enterPassword")]
 public String Password { get; set;