I declared an enum:
public enum HeightTypes{ Tall, Short}
Now I want to use it on my razor page like this:
@if (Model.Met
You have an error in your enum declaration (remove the trailing ;
):
public enum HeightTypes { Short = 0, Tall = 1 }
then the following test should work:
@if (Model.Meta.Height == HeightTypes.Tall)
{
}
you just have to make sure that your view is strongly typed and that you have brought into scope the namespace in which the Height enum is defined:
@using SomeAppName.Models
@model SomeViewModel
or reference the enum like this:
@if (Model.Meta.Height == SomeAppName.Models.HeightTypes.Tall)
{
}
But to avoid doing this in all your razor views that require using this enum, it is easier to declare it in the
section in the ~/Views/web.config
: