0

"The type or namespace name Display cannot be found ... " "The type or namespace name Name cannot be found ... "

public enum MyEnum
{
  [Display(Name = "The First")]
  first = 1,
  [Display(Name = "The Second")]
  second,
  [Display(Name = "The Third")]
  third= 1
}

I tried [DisplayName("The First")] and that is only valid for a Class, Method Property, or Event...

What am I missing here?

UDPATE: Needed [Description()] so...

public enum MyEnum
{
  [Description("The First")]
  first = 1,
  [Description("The Second")]
  second,
  [Description("The Third")]
  third= 1
}
jeffcodes
  • 726
  • 2
  • 8
  • 20

2 Answers2

0

If someone ends up here because they are looking for the DisplayAttribute, it lives in the System.ComponentModel.DataAnnotations namespace. What makes things confusing is that you can add a using directive for this particular namespace, and it won't complain... but it won't find DisplayAttribute either. It stays greyed out as if the directive is unnecessary.

Right-click on "References" in your project and select "System.ComponentModel.DataAnnotations".

The using directive will turn black, and the Display attribute will be recognized.

enter image description here

Grant Winney
  • 65,241
  • 13
  • 115
  • 165
  • 1
    Good point here. This was not my particular need. However, I'm going to accept this answer as I do believe others who come here will likely need this info. – jeffcodes Jan 25 '19 at 19:23
-1

You might wanna use Description.

public enum MyEnum
{
  [Description(Name = "The First")]
  first = 1,
  [Description(Name = "The Second")]
  second =2,
  [DisDescriptionplay(Name = "The Third")]
  third= 1
}
Bruno Caceiro
  • 7,035
  • 1
  • 26
  • 45