Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6120125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:37:57+00:00 2026-05-23T15:37:57+00:00

I declared an enum: public enum HeightTypes{ Tall, Short} Now I want to use

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:37:57+00:00Added an answer on May 23, 2026 at 3:37 pm

    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 <namespaces> section in the ~/Views/web.config:

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
          <namespaces>
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Routing" />
            <add namespace="SomeAppName.Models" />
          </namespaces>
        </pages>
    </system.web.webPages.razor>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have an enum declared like this: typedef enum { Top, Bottom, Center
in java an enum can be declared like this enum MyEnum { ONE(descr for
i have a class and have declared an enum in it like public enum
I want to declare a new enum with non-default underlying type. This works: public
I have the following enum declared: public enum TransactionTypeCode { Shipment = 'S', Receipt
I have declared an enum in my server code, and would like my client
When I declare a enum variable like this: enum paint_colors { RED, GREEN, BLUE,
I have this basic setup: enum{ BASE, PRIMITIVE, ... }; class IUnknown{ public: bool
I have declared the following Enum: public enum AfpRecordId { BRG = 0xD3A8C6, ERG
If I use /clr:oldSyntax the following should work: public __value enum IceCreamFlavors { Vanilla,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.