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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:00:44+00:00 2026-05-21T11:00:44+00:00

I have a view with a model of type List<string> and I want to

  • 0

I have a view with a model of type List<string> and I want to place a drop down list on the page that contains all strings from the list as items in the drop down. I am new to MVC, how would I accomplish this?

I tried this:

@model List<string>
@Html.DropDownListFor(x => x)

but that threw an error.

  • 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-21T11:00:44+00:00Added an answer on May 21, 2026 at 11:00 am

    To make a dropdown list you need two properties:

    1. a property to which you will bind to (usually a scalar property of type integer or string)
    2. a list of items containing two properties (one for the values and one for the text)

    In your case you only have a list of string which cannot be exploited to create a usable drop down list.

    While for number 2. you could have the value and the text be the same you need a property to bind to. You could use a weakly typed version of the helper:

    @model List<string>
    @Html.DropDownList(
        "Foo", 
        new SelectList(
            Model.Select(x => new { Value = x, Text = x }),
            "Value",
            "Text"
        )
    )
    

    where Foo will be the name of the ddl and used by the default model binder. So the generated markup might look something like this:

    <select name="Foo" id="Foo">
        <option value="item 1">item 1</option>
        <option value="item 2">item 2</option>
        <option value="item 3">item 3</option>
        ...
    </select>
    

    This being said a far better view model for a drop down list is the following:

    public class MyListModel
    {
        public string SelectedItemId { get; set; }
        public IEnumerable<SelectListItem> Items { get; set; }
    }
    

    and then:

    @model MyListModel
    @Html.DropDownListFor(
        x => x.SelectedItemId,
        new SelectList(Model.Items, "Value", "Text")
    )
    

    and if you wanted to preselect some option in this list all you need to do is to set the SelectedItemId property of this view model to the corresponding Value of some element in the Items collection.

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

Sidebar

Related Questions

I have a view model that contains a Product class type and an IEnumerable<
I have a ViewModel that contains a Product type and an IEnumerable< Product >
I have a view model that looks like this public class ViewModelRound2 { public
I have a view model with a couple of properties that are not displaying
I have a view model that is displayed in a view that uses uploadify.
I have a view, that is of Inherits from System.Web.Mvc.ViewPage<P> . Type P has
I have created a strongly type view. I want to pass IEnumerable Object or
I was trying to populate a drop down list in a view which led
Hello I have a view that deletes order numbers. Once a string has been
I have a view model like so that is created from my validator. public

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.