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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:17:24+00:00 2026-05-27T20:17:24+00:00

I want to create a DropDownList with a binding for one of my model

  • 0

I want to create a DropDownList with a binding for one of my model data, but i want the dropdown items to be built within the View and i do not want the items coming in the Model data or from my controller. Can you please suggest how to build the selectlist within View
Basically I want to create something like this:

<%= Html.DropDownListFor(model=>model.SomeProperty,<<create the dropdown list items here>> %>

Please suggest.

-Sampat.

  • 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-27T20:17:24+00:00Added an answer on May 27, 2026 at 8:17 pm

    You can’t use it that way. As the name suggests its for returning an HTML select element for each property in the object that is represented by the specified expression using the specified list items and HTML attributes.

    Though you can create this list object in view like following :-

    @Html.DropDownListFor(model => model.DropDownElement, 
                           new SelectList(model.DropDownElement, "Id", "Name"))
    

    Update

    I will take the example of a Country Model with an Id/Name pair. Like following

    public class Country 
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
    

    Now, in your controller action, you can pass it as a selectlist:

    public ActionResult YourAction()
    {
        YourModel yourModel = new YourModel(); // Just for reference. I suppose you must be passing some model to your view
        ViewBag.DropDownList = new SelectList(db.Countries, "Id", "Name"); // This way you don't need to make any changes with your passing model.
        return View(yourModel);
    }
    

    And finally in View, you can use the DropDownListFor in the following manner.

    @Html.DropDownListFor(model => model.YourModelProperty, 
       (IEnumerable<SelectListItem>)ViewBag.DropDownList, "---Select a value---") 
    

    On a Sidenote, if you just want to display a list of numbers with value, you can directly enter the HTML and utilize it, rather than using the DropDownListFor. Like follwing

    <select id="yourModelPropertyName" name="yourModelPropertyName">
       <option value="">---Select Value---</option>
       <option value="1">India</option>
       <option value="2">Australia</option>
       <option value="3">US</option>
       <option value="4">England</option>
       <option value="5">Finland</option>
    </select>
    

    Just make sure that “yourModelPropertyName” is correct and it should be the one for the property where you want it updated

    More update

    In the views where you wan’t to show the selected value, use below code

    <select id="yourModelPropertyName" name="yourModelPropertyName">
       <option selected="selected" value="1">@model.YourDropDownList</option>
       <option value="2">India</option>
       <option value="3">Australia</option>
    </select>
    

    This shall do the trick 🙂

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

Sidebar

Related Questions

I am binding a List to a DropDownList. But I want to give other
I want to create a dynamic DropDownList in ASP.NET, but after postback the DropDownList
I can create a dropdown list with items from the ViewBag, but there doesn't
I want to create a dropdownlist in my asp.net MVC2 view and I am
I want to create a dropdown list with a list of spoken languages (English,
i want create a custom json data from the mssql 2008 results so that
I want create module which update list of usb devices automatically (not only mass
i want to create a Dropdownlist with specific numbers in MVC So in my
I have a model called managers, I want to create a drop down list
I want to create a dropdownlist with selectedValue following below code: public static IEnumerable<SelectListItem>

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.