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 6939029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:34:00+00:00 2026-05-27T12:34:00+00:00

I have the following enumerator in my code: Public Enum UserSearchFields LastName FirstName Email

  • 0

I have the following enumerator in my code:

Public Enum UserSearchFields
    LastName
    FirstName
    Email
    UniqueID
End Enum

I try to populate a drop down list in the view with the values from this enumerator:

            <select id="search_type">
                <option value="@UserSearchFields.LastName" selected="selected">Last Name</option>
                <option value="@UserSearchFields.FirstName">First Name</option>
                <option value="@UserSearchFields.Email">E-mail</option>
                <option value="@UserSearchFields.UniqueID">Unique ID</option>
            </select>

But for some reason when page is rendered the value field contains the string representations of the enumerator not the underlying integer values. For example the option value field will be “LastName” instead of “0”… Why is this the case and am I making some sort of mistake?

P.S. I’m aware that I can populate a drop down list from an Enumerator such as How do you create a dropdownlist from an enum in ASP.NET MVC? but i just would like to know why is this issue happening?

  • 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-27T12:34:00+00:00Added an answer on May 27, 2026 at 12:34 pm

    I think you need to set the enums to a number like so:

    Public Enum UserSearchFields
        LastName = 0
        FirstName = 1
        Email = 2
        UniqueID = 3
    End Enum
    

    Even if this is an unecessary step, you need to cast it to an int when you write it out like so:

    <select id="search_type" style="width: 100%;">
        <option value="@((int)SOLEPortal.UserSearchFields.LastName)" selected="selected">Last Name</option>
        <option value="@(((int)SOLEPortal.UserSearchFields.FirstName)">First Name</option>
        <option value="@((int)SOLEPortal.UserSearchFields.Email)">E-mail</option>
        <option value="@((int)SOLEPortal.UserSearchFields.UniqueID)">Unique ID</option>
    </select>
    

    A better way to do this would be to create an extension method that automatically writes out a drop down list from an enum, but this is a good starting place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with the following code: public static void RestoreToolStripMenuItem(ToolStripMenuItem item, List<string>.Enumerator
I have the following enumeration: public enum AuthenticationMethod { FORMS = 1, WINDOWSAUTHENTICATION =
I have the following code: public class DataReader<T> where T : class { public
I have an enumeration that looks like the following public enum MyEnum { A,
I have the following enumeration Enum NodeStatusTypes Undefined Grant Deny End Enum and I'm
Say I have the following code (context narrowed down as to keep the question
Hi, I have the following code to create a tree from the current AD
I have some code which gets resources as follows: public static final String CONVERTER_FILE
Hi I have the following code, the filter call back gets called but the
I have following entity class User: public class User implements Serializable { @Column(length =

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.