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

  • Home
  • SEARCH
  • 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 3606492
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:15:18+00:00 2026-05-18T21:15:18+00:00

I know this has been asked a few times before, but the existing solutions

  • 0

I know this has been asked a few times before, but the existing solutions look like hacks rather than a proper pattern.

I have a simple drop down list. I am trying to populate it with data and have a item pre selected. I am succeeding at the ‘populate it with data part’ but failing to get my preferred item pre-selected.

I am using ASP.NET MVC 3 RC2.

The important code bits:

{
    // Bunch of code
    CategoryOptions = new SelectList(categories, "Id", "Slug", article.Category.Id);
}

Now… the CategoryOptions is being passed to the Html helper like so:

@Html.DropDownListFor(a => a.Category, Model.CategoryOptions)

I have looked at the values being passed into the helper and have confirmed that one of the items has the selected value set to true:

alt text

However, it is not reflecting in the Html being generated by the helper. None of the … tags have the selected=”selected” attribute.

I used Reflector to examine the code a bit, and this line (SelectExtensions.SelectInternal) looks dicey:

item.Selected = (item.Value != null) ? set.Contains(item.Value) : set.Contains(item.Text);

Am I doing something wrong here? Or is the framework (ASP.NET MVC 3 RC2) at fault here.

  • 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-18T21:15:19+00:00Added an answer on May 18, 2026 at 9:15 pm

    Ok… I just fixed it.

    I changed around my view model to use a CategoryId instead of a Category slug. So now, my view looks like:

    @Html.DropDownListFor(a => a.CategoryId, Model.CategoryOptions, new { @class = "ask-category-field" })
    

    I think the model value being select (in this case, a => a.CategoryId) has to have the same type as the selected ‘value.’ (I will refine this explanation when I get more time to go over the framework code.) But clever coding indeed 🙂 Hats of to ASP.NET MVC devs.

    Now, it works perfectly as expect and also retains changes to the selected item across a PRG lifecycle.

    Hope this helps someone.

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

Sidebar

Related Questions

I know this has been asked a few times here. But none of the
I know this question has been asked few times over SO but none of
Now I know this has been asked a few times, but i'm still not
I know this kind of question has been asked a few times, but alot
I know this question has been asked before, but I ran into a problem.
I know this question has been asked a bit before. But looking around I
I know this specific question has been asked before , but I am not
I know that this question has been asked many times before in different guises
I know this has been asked a lot of times in StackOverflow already, but
I know this has been asked many times, but I don't understand what is

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.