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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:40:22+00:00 2026-06-05T16:40:22+00:00

I have a view with 1 dropdown generated from Model property and 3 additional

  • 0

I have a view with 1 dropdown generated from Model property and 3 additional dropdowns that are generated from array property

@Html.DropDownListFor(m => m.AgentType, Model.AgentTypeListItems)
@for (int i = 0; i < Model.AgentTypes.Length; i++)
{
    @Html.DropDownListFor(m => m.AgentTypes[i], Model.AgentTypeListItems)
}

The controller method initializes AgentTypeListItems collection + sets default values for AgentType dropdown and 3 dropdowns for the collection:

var model = new OptionsViewModel();

// for DropDownListFor
model.AgentTypeListItems = new[]
{
    new SelectListItem { Text = "1", Value = "1" }, 
    new SelectListItem { Text = "2", Value = "2" },
    new SelectListItem { Text = "3", Value = "3" },
};

// 1 dropdown in the model
model.AgentType = "2";

// 3 dropdowns in array
model.AgentTypes = new[] { "3", "2", "1" };

return View(model);

When I open it in browser I get “2” everywhere though AgentTypes array was initialized with different values(!):

this is wrong

When I replace DropDownListFor with TextBoxFor:

@Html.TextBoxFor(m => m.AgentTypes[i])

I get the correct values in the inputs (!):

this is how it should be

It means the TextBoxFor works as expected, but DropDownListFor doesn’t.

Is it a bug in MVC DropDownListFor?

UPDATE
Here is the model class:

public class OptionsViewModel
{
    public SelectListItem[] AgentTypeListItems { get; set; }
    public string AgentType { get; set; }
    public string[] AgentTypes { get; set; }
}
  • 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-05T16:40:25+00:00Added an answer on June 5, 2026 at 4:40 pm

    I know that this post is more than a year old but it seems still to be a bug. Replacing

    @Html.DropDownListFor(m => m.AgentType, Model.AgentTypeListItems)
    @for (int i = 0; i < Model.AgentTypes.Length; i++)
    {
        @Html.DropDownListFor(m => m.AgentTypes[i], Model.AgentTypeListItems)
    }
    

    with

    @Html.DropDownListFor(m => m.AgentType, Model.AgentTypeListItems)
    @for (int i = 0; i < Model.AgentTypes.Length; i++)
    {
        @Html.DropDownListFor(m => m.AgentTypes[i], new SelectList(Model.AgentTypeListItems, "Value", "Text", Model.AgentTypes[i])
    }
    

    works for me.

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

Sidebar

Related Questions

So I have this on my view: <%= Html.Encode(Model.STPData.ProjectName)%> Now say instead of having
I have a view that list Parts in a htmltable format from a database
I have a view where I use a dropdown list with enum: public enum
I have a html structure like : <div onmouseover=enable_dropdown(1); onmouseout=disable_dropdown(1);> My Groups <a href=#>(view
I am beginner in rails. I have view that i try to print inside
I have a select dropdown where I generate the options from database entries, then
I have a dropdown <select> field which gets its values from the db. I'm
I have a spinner that show my data list from a database SQLite.. I
In a user contorl I need to have a asp.net grid view with dropdown,text
I have a view with a form. On that form I have some textboxes

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.