I’m pretty new to MVC, but I have the following code:
<td>
@Html.DisplayFor(modelItem => item.Status)
@switch (item.Status)
{
case 0: Html.DisplayText("Requested");
break;
case 1: Html.DisplayText("In Progress");
break;
case 2: Html.DisplayText("Declined");
break;
default:
Html.DisplayText("Undefined");
break;
}
</td>
It renders the “Html.DisplayFor” fine, this is an integer. But really I want to display the equivalent text based on the item.Status in that same position. But this is not working. I could change the way the original class handles the status in the Get and Set methods but how would I do it this way?
You could create a property on your ViewModel that does this logic for you. Such as
And in your view, replace the switch statement with