I have the following code on a CSHTML razor page:
@{ var sort = ViewBag.Sort.ToString(); switch (sort) { case "None": Html.Action("SortNone"); break; case "Name": Html.Action("SortName"); break; case "Date": Html.Action("SortDate"); break; } }
However, this does not work with a compiler error message:
CS0151: A switch expression or case label must be a bool, char, string, integral, enum, or corresponding nullable type
But sorting is a line! Rewriting this as a sequence of if / else statements works, but not so elegantly.
source share