I have an enum type that is localized using DisplayAttribute, a resource file and aspnetcore built in localization support. I can successfully verify that the localization works in a view by for example using
Html.GetEnumSelectList<TypeExample>().
How can I get the same localized DisplayAttribute in a controller or even a Model.
I tried using code like:
var name = TypeExample.A.GetType()?
.GetMember(TypeExample.A.ToString())?
.FirstOrDefault()?
.GetCustomAttribute<DisplayAttribute>()?.GetName();
but it does not return the localized display name.
I would like to use it in a model for an ApiController eg.
public class Model
{
public TypeExample Type { get; set; }
public string TypeDisplayValue => Type.GetDisplayValue()
}