I have an enum OType as:
public enum OType
{
First_enum_option,
Second_enum_option,
None_of_the_above
}
My model has an enum field EType of this type, which is displayed in the view as:
@Html.DisplayFor(x => x.EType)
In the view, the option is displayed correctly. But I want to replace underscores with spaces. With normal strings, I usually do this with Replace("_", " ")
If I use: @Html.DisplayFor(x => x.EType.ToString().Replace("_", " "))
, I get this System.InvalidOperationException with message:
Templates can be used only with field access, property access, single-dimension >array index, or single-parameter custom indexer expressions.
I have thought of this solution:
<td>
@{
string str = item.EType.ToString().Replace("_", " ");
}
@str
</td>
This solves the problem. Is there any concise and elegant way to achieve this?