Asp.net-mvc – MVC 4 setting attributes values from resources

asp.netasp.net-mvcasp.net-mvc-4embedded-resourceresources

I am trying to the following thing:

 [Display(Name = Resources.LcmsBs.Models.UserName)]
 [ToolTip(Resources.LcmsBs.ToolTips.UserName)]
 public string UserName { get; set; }

I am getting the following compilation error :

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

What is the best practice to avoid hard coded constants in code ?
Is it possible to set attributes values from the resources ?

Best Answer

You've got a slightly different question but the answer to the following could be applied to your question

DataAnnotations and Resources don't play nicely

Something like the following

[Display(ResourceType = typeof(Resources.LcmsBs.Models), Name = "UserName")]