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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:40:41+00:00 2026-05-16T02:40:41+00:00

As far as I can tell, there are 3 ways to create a DropDownList

  • 0

As far as I can tell, there are 3 ways to create a DropDownList in an ASP.NET MVC View:

  1. Hand code the HTML manually
  2. <asp:DropDownList ID="someID" runat="server"></asp:DropDownList>
  3. <%= Html.DropDownList("someID") %>

I think we can all agree that #1 is (generally) a waste of time.

With #2, it appears to be the “WebForms” way of doing it, but has an advantage in that if you’re writing a View you can have access to the object you’ve created via inline code that occurs after it. For example:

<asp:DropDownList ID="someID" runat="server"></asp:DropDownList>
<% 
   someID.SelectedIndex = 0;  
   string someString = someID.SelectedValue.ToString();
%>

This does not appear to be possible with #3.

The nice thing that I’ve discovered about #3 (the HTML Helper way) is that by passing it a string, it sets the Name and ID to the string as well as uses the string to search the ViewData dictionary and auto-generate the respective tags for the DropDownList based on the SelectList that was added to the ViewData dictionary that was added in the calling Controller.

// controller code
ViewData["someID"] = new SelectList(someMethod().ToList());  

For the life of me, I cannot figure out if there is a way to auto-generate the tags with <asp:DropDownList> or if I have to manually create them myself.

What’s generally the best approach for implementing a DropDownList in ASP.NET MVC?

  • 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-16T02:40:42+00:00Added an answer on May 16, 2026 at 2:40 am
    <%= Html.DropDownList("name", new SelectList(someEnumerable, "valueProperty", "textProperty")) %>
    

    where someEnumerable is a property on your viewModel.

    for example:

    class Person
    {
        int id;
        string name;
    }
    
    class myVM
    {
        IEnumerable<Person> people;
    }
    
    <%= Html.DropDownList("name", new SelectList(Model.people, "id", "name")) %>
    

    Edit dont make the SelectList in your controller, this is view specific code and belongs in the view, just send your IEnumerable in the viewmodel.

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

Sidebar

Related Questions

As far as I can tell, there are two main ways of creating functions
I'm pretty new to QGraphicsView in Qt. As far as I can tell there
As far as I can tell, there is no API (official or unofficial) to
As far as I can tell, this code is fine, and should display some
I am an MVC newbie. As far as I can tell: Controller : deals
I am new to javascript. As far as I can tell there are 5
As far as I can tell there's no simple way of retrieving a character
Just stared using Haskell and realized (at far as I can tell) there is
As far as I can tell i'm doing everything by the book, but the
As far as I can tell, Scala has definitions for the Enumeration Value class

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.