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

The Archive Base Latest Questions

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

In my controller I generated a SelectList that I pass to the dropdown helper:

  • 0

In my controller I generated a SelectList that I pass to the dropdown helper:

  <%= Html.DropDownList("abc123", Model.SomeList) %>

I look at the querystring for a value, which is a ID.

I then loop through all the items in the SelectList and if it is equal to the ID, I do:

item.Selected = true;

The controller action then passes this SelectList to the view and then to the Html helper.

In debug mode I can see the value does get set to true, but the html renders without selecting the item.

What can the issue be?

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

    I don’t know what you are doing wrong as you’ve shown 0 code but this definitely works:

    public ActionResult Index(int? id)
    {
        var model = new SelectList(new[]
        {
            new { Id = 1, Name = "item 1" },
            new { Id = 2, Name = "item 2" },
        }, "Id", "Name", id);
        return View(model);
    }
    

    and in your view:

    <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SelectList>" %>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
        <%= Html.DropDownList("abc123", Model) %>
    
    </asp:Content>
    

    Now if you navigate to /home/index/1 the first item is selected, if you navigate to /home/index/2 the second item item selected.

    Also if you are using ASP.NET MVC 2.0 I would recommend you the strongly typed DropDownListFor helper instead of DropDownList.

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

Sidebar

Related Questions

I have a DropDownList populated with a SelectList generated from (an anonymous type) that
i will pass the value generated by this calendar_date_select to the controller. onchange code
I want the Roo-generated JSON controller stuff. I don't want the full HTML scaffolding
When I post a 'Model' object (as generated by LinqToSQL) to a controller, I
I'm writing some unit tests for an ASP.NET MVC controller that's using SubSonic3 generated
Using MvcScaffolding with EF4.1, I see that the first generated line of a Controller
I generated a controller called Search. later I built a model called search as
I’ve got a question about the default account model, view and controller generated when
I'm passing from the controller an array generated by the next code: public ActionResult
I need to test a controller, of action index (generated by the grails generate-all

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.