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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:36:32+00:00 2026-05-29T03:36:32+00:00

You can create a dropdownlist using @Html.DropDownListFor(model => model.SelectedId, model.DropDownItems); but where does DropDownListFor

  • 0

You can create a dropdownlist using

@Html.DropDownListFor(model => model.SelectedId, model.DropDownItems);

but where does DropDownListFor get the value to pass into the model => model.SelectedId lambda from?

  • 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-29T03:36:33+00:00Added an answer on May 29, 2026 at 3:36 am

    SelectedId is just the integer of the field in the model.

    the model is passed in from the controller using

    return View(myModel);
    

    And the model can be defined in the view at the top

    @model mymodelnamespace.RoomBookingInsert
    

    So the dropdownbox’s value is set as the SelectedId field in your model.

    A proper field name for example would be RoomNo if that clarifies it better.

    @Html.DropDownListFor(model => model.RoomNo, model.Rooms);
    

    As long as model.DropDownItems (or model.Rooms in my example) Contains a item with the value of that attribute, it will set it as the selected item in the list as default.

    Edit:

    If you are using viewbag, rather than the model, instead use DropDownList. (each input has a for extension for use with models)

    @Html.DropDownList("RoomNo", 
           new SelectList(ViewBag.Rooms as System.Collections.IEnumerable ?? Enumerable.Empty<SelectListItem>(), "RoomNo", "RoomName"),
           new { @value = @ViewBag.RoomNo})
    

    This above, creates an input form with id RoomNo,

    and uses a SelectList that will default to empty if null. The fields that defined the values and text shown are set at the end of the select list parameters.

    The last bit sets the default value to the contents of @ViewBag.RoomNo.

    You can also create the select list in the controller, and then simply set the dropdown options to the viewbag.myselectList entity.

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

Sidebar

Related Questions

I have created a partial view that displays a dropdownlist html.DropDownListFor(m => m.SelectOption, Model.SelectOption)
I create a dropdown list by using ASP.NET MVC helper like this, <%=Html.DropDownList(Group,-please select
I'm trying to use the Html.DropDownList extension method but can't figure out how to
I can create the following and reference it using area[0].states[0] area[0].cities[0] var area =
I can create a literal long by appending an L to the value; why
I can create a contact that is not mail enabled, but how do I
I can create an array of buttons in Windows Form but how can i
I can create a sparse php array (or map) using the command: $myarray =
I can create new Silverlight App with .NET RIA Services enabled. But when I
I'm trying to produce a dropdownlist for GetAllRoles using the role provider. I can

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.