I declared an enum:
public enum HeightTypes{ Tall, Short}
Now I want to use it on my razor page like this:
@if (Model.Meta.Height == HeightTypes.Tall)
But there’s a problem as I get an error. Is there some way I can tell the razor page about my enum?
You have an error in your enum declaration (remove the trailing
;):then the following test should work:
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:
or reference the enum like this:
But to avoid doing this in all your razor views that require using this enum, it is easier to declare it in the
<namespaces>section in the~/Views/web.config: