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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:10:48+00:00 2026-05-22T15:10:48+00:00

I’m pulling my hair out here. I’m using the DropDownListFor HTML helper in MVC3

  • 0

I’m pulling my hair out here. I’m using the DropDownListFor HTML helper in MVC3 with Enums like so:

@Html.DropDownListFor(model => model.Title, Enum.GetValues(typeof(ICS_Signup_Form.Models.Titles)).Cast<ICS_Signup_Form.Models.Titles>().Select(x => new SelectListItem { Text = x.ToString().ToFriendlyString(), Value = x.ToString() }), new { @class = "styled" })

My enum looks like so: public enum Titles { Mr, Dr, Miss, Mrs, Ms, Other };

If Model.Title equals “Other” then the drop down list doesn’t select this value, there’s no selected="selected" in the HTML. I’ve tried adding the property Selected to SelectListItem: Selected = (x.ToString() == Model.Title) and the expression works fine when I’m stepping through my code, as expected but the selected value is always “Mr” (the first in the list).

What’s even weirder this works perfectly fine (as do the other 7 drop down boxes I have in my project):

@Html.DropDownListFor(model => model.BusinessStatus, Enum.GetValues(typeof(ICS_Signup_Form.Models.BusinessTypes)).Cast<ICS_Signup_Form.Models.BusinessTypes>().Select(x => new SelectListItem { Text = x.ToString().ToFriendlyString(), Value = x.ToString() }), new { @class = "styled" })

With the enum: public enum BusinessTypes { Charity, Government, Limited, LLP, Partnership, PLC, SoleTrader };

The difference? None.. Any ideas?

  • 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-22T15:10:49+00:00Added an answer on May 22, 2026 at 3:10 pm

    tldr; change the name of your DropDownList to something else

    I had the same problem (albeit in ASPX engine, which I believe doesn’t make any difference in this case). Here’s how to repro it:

    the codebehind (note “Selected = true” in the second item):

    List<SelectListItem> teams = new List<SelectListItem>();
    teams.Add(new SelectListItem { Text = "Slackers", Selected = false, Value = "0" });
    teams.Add(new SelectListItem { Text = "Workers", Selected = true, Value = "1" });
    ViewData["teams"] = teams;
    

    the ASPX code:

    <%: Html.DropDownList("team", (IEnumerable<SelectListItem>)ViewData["teams"]) %>
    

    It reproes: you can see that the first item gets selected automatically and neither of the items have the “selected” option in HTML. Here’s the generated HTML which reproes it:

    <select id="team" name="team">
    <option value="0">Slackers</option>
    <option value="1">Workers</option>
    </select>
    

    Solution: Turns out some of the element names cause the ASPX rendering engine to behave differently. In my case, I just changed the DropDownList name from “team” to “defaultteam” — and it started working:

    Here’s WORKING ASPX code:

    <%: Html.DropDownList("defaultteam", (IEnumerable<SelectListItem>)ViewData["teams"]) %>
    

    and here is the HTML generated by it:

    <select id="defaultteam" name="defaultteam">
    <option value="0">Slackers</option>
    <option selected="selected" value="1">Workers</option>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.