I need to display the name of the enum for corresponding value inside DisplayFor HtmlHelper. I have the following enum:
public enum CheckStatus
{
Yes = 1,
No = 2,
Maybe =3
}
I'm displaying values for a model normally like this:
@Html.DisplayFor(modelItem => item.Name)
The problem is that at one point I have this:
@Html.DisplayFor(modelItem => item.Status)
That line displays only status value which is set before from enum (1,2 or 3). Instead of that I need somehow to display name for that value. So, if status code is 2, I want to display 'No', not number 2.
I had the similar problem with getting enum names when I was populating dropdown list and I managed to solve it like this:
@Html.DropDownListFor(model => model.Item.Status,
new SelectList(Enum.GetValues(typeof(Pro.Web.Models.Enums.CheckStatus))))
I am a little bit lost in how to get only that one name from the value of the enum.
Thank you for your help.