1

Say, I have an MVC model

public class MyModel
{
    [Display(Name = "Sophistically-named field", Description = "blah-blah")]
    public int SophisticallyNamedField {get;set;}
}

Is there any way I can get field's name and description from annotation? I need to get it in C# code, not in Razor.

Arnthor
  • 2,563
  • 6
  • 34
  • 54

1 Answers1

0

Use Reflection to access the values of a given Attribute. You might want to check out the GetCustomAttribute method or have a look at one of the countless samples on this site.

Community
  • 1
  • 1
Mats
  • 14,902
  • 33
  • 78
  • 110