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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:08:30+00:00 2026-06-03T17:08:30+00:00

I am using ASP.Net MVC 2 and have trouble getting a DropDownList to bind

  • 0

I am using ASP.Net MVC 2 and have trouble getting a DropDownList to bind properly.

I am using a strongly typed ViewModel and the HTML.DropDownListFor statement to create the dropdown in my View. The statement works fine in the ‘normal’ scenario where I just bind the DropDown to a simple field in my ViewModel.
I am having trouble using this scenario when my ViewModel contain a List (array) of multiple objects where I want a field in each of these objects to bind to a (seperate) DropDown. In that case the DropDown’s do not get the correct initial value.

For example the case where we have a person that can have multiple addresses. Each address consists of a Street, a City and a State. I want the state to be displayed as a DropDown.
My model is:

public class PersonModel : CommonViewModel
{
    public IList<SelectListItem> AvailableStates { get; set; }

    public string Name { get; set; }

    public IList<AddressModel> Addresses { get; set; }

    public PersonModel()
    {
        AvailableStates = GenerateStates();
    }

    private IList<SelectListItem> GenerateStates()
    {
        List<SelectListItem> items = new List<SelectListItem>();
        items.Add(new SelectListItem() { Text = "WA", Value = "WA" });
        items.Add(new SelectListItem() { Text = "NY", Value = "NY" });
        items.Add(new SelectListItem() { Text = "IH", Value = "IH" });
        items.Add(new SelectListItem() { Text = "FL", Value = "FL" });
        items.Add(new SelectListItem() { Text = "CA", Value = "CA" });

        return items;
    }
}

public class AddressModel
{
    public string Street { get; set; }
    public string City { get; set; }
    public string State { get; set; }
}

Now in my View I want to use something like:

<% using (Html.BeginForm("SubmitPersonDetails", "Home", new { actionMode = "Person"}, FormMethod.Post, new { id = "SubmitPersonForm" }))
   {%>
    <div class="formrow longinput">
    <%= Html.LabelFor(person => person.Name)%>
    <%= Html.TextBoxFor(person => person.Name)%>
</div>
<h4>Addresses</h4>
<% for (int i = 0; i < Model.Addresses.Count; i++) { %>
<div class="formrow">
<%= Html.TextBoxFor(person => person.Addresses[i].Street)%>
<%= Html.TextBoxFor(person => person.Addresses[i].City)%>
<%--<%= Html.TextBoxFor(person => person.Addresses[i].State)%>--%>
<%= Html.DropDownListFor(person => person.Addresses[i].State, Model.AvailableStates) %>
</div>
<% } %>
 <input class="button primary" type="submit" value="Submit" name="Submit" />
<% } %>

For the Textboxes this works fine (also if I just use a textbox for State, see the commented out bit). The DropDown’s are generated correctly but not set to the correct value. If I select a value in the DropDowns and submit the form the correct values are put back into my model.

I also tried putting the Address part in a UserControl, which is then rendered several time. If I render the UserControl using Html.RenderPartial the correct values are set in the DropDOwn’s but on Postback my model isn’t populated correctly. If I render the UserControl using EditorFor I get the same problem as with the code above: the DropDown’s don’t get the correct initial value but on Postback I do get the selected values set in my model.

Another thing I tried is making the Addresses not a List but instead hardcoding several addresses in my View Model (properties: Address1, Address2, Address3) and then using:
<%= Html.DropDownListFor(person => person.Address1.State, Model.AvailableStates) %>
In this case the DropDown does get the correct value. Obviously I don’t want to use this workaround for lack of flexibility.

What am I doing wrong? I am new to MVC so maybe it is my whole approach that is wrong?

  • 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-03T17:08:32+00:00Added an answer on June 3, 2026 at 5:08 pm

    That’s a limitation of the DropDownListFor helper which is not able to extract the value from a complex lambda expression such as the one you are using (a lambda expression containing array index access). One possible workaround is the following:

    <%= Html.DropDownListFor(
        person => person.Addresses[i].State, 
        new SelectList(
            Model.AvailableStates, 
            "Text", 
            "Value", 
            Model.Addresses[i].State
        )
    ) %>
    

    It’s a bit ugly as we are now passing the same value in the SelectList constructor but this time the DropDownListFor helper will be able to properly set the corresponding option.

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

Sidebar

Related Questions

I have a ASP.NET MVC site using Membership Provider. I have trouble testing some
I'm using ASP.NET MVC and have a model which has an image (byte array)
I'm using ASP.NET MVC 2 and have a login page that is secured via
Using ASP.Net MVC on my Site.Master I have: <head runat=server> <title><asp:ContentPlaceHolder ID=TitleContent runat=server />
Using ASP.NET MVC 2.0, I have an actionlink that is used for comments on
I'm using ASP.NET MVC RC2. I have a set of classes that were auto-generated
I wrote an application using ASP.NET MVC, in this application I have an Index
I am using ASP.NET MVC 1.0. I have an ActionResult which receives a form
we have a mixed development environment using ASP.NET MVC and Ruby on Rails. We
I have build a webapplication using ASP.NET MVC and JQuery. On my local machine

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.