I am trying to retrieve the [Display]
text below for whichever enum is saved in the database (i.e., if None, then corresponding is "No thanks.") without having to code an @if
block in my view. I guess it's not possible, but thought I would ask.
public enum MyEnum
{
[Display(Name = "No thanks.")]
None,
[Display(Name = "Yes, send me your 100 Packet.")]
100Packet,
[Display(Name = "Yes, send me your 200 Packet.")]
200Packet
}
Right now, the only solution I have is to do this in my view:
@Model.MyEnumRadioButton // displays saved item in DB (i.e., "100Packet")
@if (Model.MyEnumRadioButton == MyEnum.None)
{
<text>No thanks.</text>
}
....
and repeat that for each item in the enum
. For this small example it's no big deal, but I have a lot of different enum
's, some with up to 10 choices.
For example, is there something I can do with the @Model.MyEnumRadioButton
to make it display the text?
Any thoughts? Thanks in advance.