Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 4 setting attributes values from resources

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 ?

like image 241
StringBuilder Avatar asked Nov 13 '12 10:11

StringBuilder


1 Answers

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")]
like image 123
dove Avatar answered Oct 03 '22 15:10

dove