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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:09:28+00:00 2026-05-22T18:09:28+00:00

In my MVC 3 Razor app, I have a Model with an enum.. Model

  • 0

In my MVC 3 Razor app, I have a Model with an enum..

Model Example:

public class EmployeeModel
{
 public enum Title
 {
  Accountant = 111,
  Sales = 222,
  Production = 333 
 }

 [Required]
 public string Name {get; set;}

 [Required]
 public Title JobTitle {get; set;}
}

In my View I would like to use the Html helpers to build an Html Form…

View Example:

@model ..Models.EmployeeModel

@using (Html.BeginForm())
{
 @Html.LabelFor(m => m.Name)
 @Html.TextBoxFor(m => m.Name)
 <br>

 @Html.LabelFor(m => m.JobTitle)
 @Html.DropDownListFor(m => m.JobTitle, ??How do I get Title enum values??)
 <br>

 <input type="submit />
}

The output of the DropDownListFor that I trying to achieve would look like this:
Note the option values match the initialized values of the enum

<select name="JobTitle">
 <option value="-1">Choose a Job Title</option>
 <option value="111">Accountant</option>
 <option value="222">Sales</option>
 <option value="333">Production</option>
</select>

How do I get the DropDownListFor<> helper to create a select/option element based on the Title enum of the Model?

Also, is it possible to have the DropDownListFor<> helper to add an extra (that is not part of the enum) similar to the “Choose a Job Title” option in the example above?

  • 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-22T18:09:29+00:00Added an answer on May 22, 2026 at 6:09 pm

    You could possibly get a String[] with the names of the enum values and create a dropdown from that. In your view model, add a property Titles of type SelectListItem and add the enum values and names to that. You can get the names and values through the System.Enum type.

    var defaultItem = new SelectListItem();
    defaultItem.Value = -1;
    defaultItem.Text = "Choose a title";
    defaultItem.Selected = true;
    model.TitleSelectItems.add(defaultItem);
    
    String[] names = System.Enum.GetNames(typeof(Title));
    Int[] values = System.Enum.GetValues(typeof(Title));
    
    for (int i = 0; i<names.Length; i++)
    {
        var item = new SelectListItem();
        item.Text = names[i];
        item.Value = values[i];
        model.TitleSelectItems.Add(item);
    }
    

    It’s kind of ugly, but it’ll work.

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

Sidebar

Related Questions

Building an MVC 3 app with Razor and I have some information persisted in
I'm developing a MVC 3 Razor Web App, in which details of multiple categories
I have a MVC 3 Razor web application that needs to allow creating and
Most of the MVC samples I have seen pass an instance of the view
What is the syntax/analogue for Assembly Directive http://msdn.microsoft.com/en-us/library/a7c375wt(VS.71).aspx in MVC 3.0 Razor On MVC
VS2010 Ultimate, ASP.NET MVC 3 w/Razor. I've created a custom view engine in my
I get an error when using razor helpers in an MVC 3 project (did
aspnet mvc has the HandleError filter that will return a view if an error
Using MVC with an observer pattern, if a user action requires polling a device
Which MVC-framework is the best option (performance/ease of development) for a web application, that

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.