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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:04:01+00:00 2026-05-26T05:04:01+00:00

May be I just don’t know how to google, but I am trying to

  • 0

May be I just don’t know how to google, but I am trying to find an example where a dropdown control is data-binded to a collection (this part is working for me) and then I want to read the drop down selection back into a variable. This variable could be a property on the mode. Binding dropdown selected value back into variable is where I am having troube. In web-forms world this was no big deal but for some reason I cannot make it work with MVC 3. Any code samples or examples will be highly appreciated.

  • 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-26T05:04:02+00:00Added an answer on May 26, 2026 at 5:04 am

    The recommended way to do this in ASP.NET MVC is to use a view model. When you design a dropdownlist you need 2 properties on this view model: one that will be used to bind the selected value to and a second one which represents a collection of values and texts which will be used to generate the options. Then you could use the first property to preselect a given option.

    So we start by designing view model:

    public class MyViewModel
    {
        public string SelectedId { get; set; }
        public IEnumerable<SelectListItem> Items { get; set; }
    }
    

    then a controller action which populate this view model:

    public ActionResult Index()
    {
        var model = new MyViewModel
        {
            // preselect the second item which has value=2
            SelectedId = "2",
    
            Items = new[]
            {
                new SelectListItem { Value = "1", Text = "item 1" },
                new SelectListItem { Value = "2", Text = "item 2" },
                new SelectListItem { Value = "3", Text = "item 3" },
            }
        };
        return View(model);
    }
    

    and in the strongly typed view use the DropDownListFor helper to generate the dropdown:

    @model MyViewModel
    @Html.DropDownListFor(
        x => x.SelectedId, 
        Model.Items,
        "-- Select an Item --"
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a bit of a newbie question, but I just don't know!
I'm trying to implement the Send button , but running into what may just
I fear this just may not be possible, but I'm trying to create a
I don't see what's wrong here, but I may just misunderstand the syntax. I'm
It's probably an already asked question, but I just don't know what are the
I may just be doing something wrong but all of my javascript files as
I'm a bit confused by the Lucene.NET API, but, it may just be a
This may be a stupid question but im just starting to learn Rail thats
This may be a really dumb question but I'm just starting to learn the
I may just need a terminology update, but I have been playing in Magento

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.