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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:35:35+00:00 2026-06-15T16:35:35+00:00

@Html.DropDownListFor(m => m.field, Model.fieldList, Select) I have the code above to get the values

  • 0
@Html.DropDownListFor(m => m.field, Model.fieldList, "Select")

I have the code above to get the values of a drop down list from a database. Because the database does not have the select value, I am add it to the list. However, I want to set the selected value to a certain value(variable). How can I do this?

Say I want the selected value to be “WI” and “WI” is in the list. How do i do this? Or how do I specify the @value property?

  • 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-06-15T16:35:36+00:00Added an answer on June 15, 2026 at 4:35 pm

    The DropDownListFor function will first look if there is a selected value in the provided select list. If there are no selected values in the selected list items, it will look at the value of the field that the drop down list is for and attempt to match that to the value of each select list item until it finds the correct one. If any select list item does not have value, it will compare it to the text instead.

    Once you have the full list generated, loop through it and find the value you want selected, then set the selected property to true and it should choose that one.

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

Sidebar

Related Questions

If I have a drop down list as follows <div class=editor-label> <%= Html.DropDownListFor(model =>
I have this code: @this.Html.DropDownListFor(vm => vm.FishId, new SelectList(this.Model.Fishies, FishId, FishName, this.Model.FishId), Please Select
I have the following set for drop down in asp.net mvc @Html.DropDownListFor(model => model.DataId,
this is my drop down list: @Html.DropDownListFor(m => m.ReportType, new SelectList(ViewBag.DateRange as List<SelectListItem>, Value,
I have multiple dropdown list: @Html.DropDownListFor(x => x.HaveColoSpace.SelectedOptions, new SelectList(Model.HaveColoSpace.Options, Value, Text), new {
`//View <tr><td>Experience level</td><td><div class=editor-field> <%: Html.DropDownListFor(model => model.ExperienceLevelID, (SelectList)ViewData[Experience], --select--)%> <%: Html.ValidationMessageFor(model => model.ExperienceLevelID)
I have a view that contains two @Html.DropDownListFor helpers: <div class=editor-field> @Html.DropDownListFor(model => model.Employee,
I have an editor template with a dropdown: @Html.DropDownListFor(m => m.AdmissionState, new List<SelectListItem>() {
i have 1 controls as following <div> Country<br /> @Html.DropDownListFor(model => model.CountryId, new SelectList(Model.CountriesList,
I have the following in my view : <div class=editor-field> @Html.DropDownListFor(x => x.Subject, (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.