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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:45:36+00:00 2026-05-16T11:45:36+00:00

I have an action called Sessies. In this action i am creating ‘Sessies’ objects

  • 0

I have an action called Sessies. In this action i am creating ‘Sessies’ objects from a form. if they don’t exist i add them in the DB, if there are already Sessies objects connected to the ‘Reeksen’ object, i load the ‘Sessies’ into the form so that they can be edited. so i have a create and edit in 1 and the same form.

Also, a ‘Reeksen’ has a predefined number of ‘Sessies’ which can not be changed. so i let the user make all ‘Sessies’ in one time (cos the amount of sessies will be from 1 to 10)

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<List<MVC2_NASTEST.Models.FlatSessie>>" %>
...
<h2>
    Sessies</h2>
<% using (Html.BeginForm()) {%>
<%= Html.ValidationSummary(true) %>
<fieldset>
    <legend>Fields</legend>
    <% for (int i = 0; i < Model.Count; i++) { %>

    <%= Html.HiddenFor(model => model[i].Ses_ID)%>
    <%= Html.HiddenFor(model => model[i].Ses_Rks_ID)%>

    <div class="editor-label">
        <%= Html.LabelFor(model => model[i].Ses_Nummer)%>
    </div>
    <div class="editor-field">
        <%= Html.HiddenFor(model => model[i].Ses_Nummer)%>
        <%= Html.Label(Model[i].Ses_Nummer.ToString())%>
    </div>

    ....

    <div class="editor-label">
        <%= Html.LabelFor(model => model[i].Ses_LG_ID)%>
    </div>
    <div class="editor-field">
        <%= Html.DropDownListFor(model => model[i].Ses_LG_ID, MVC2_NASTEST.MvcApplication.lesgeverList(), "Selecteer een lesgever...")%>
        <%= Html.ValidationMessageFor(model => model[i].Ses_LG_ID)%>
    </div>
    <div class="editor-label">
        <%= Html.LabelFor(model => model[i].Ses_Lpl_ID)%>
    </div>
    <div class="editor-field">
        <%= Html.DropDownListFor(model => model[i].Ses_Lpl_ID, (ViewData["lesplist"] as List<List<SelectListItem>>)[i], "Selecteer een lesplaats...")%>
        <%= Html.ValidationMessageFor(model => model[i].Ses_Lpl_ID)%>
    </div>
    <% } %>
    <p>
        <input type="submit" value="Create" />
    </p>

in my aspx i use a for loop which goes over the List (a FlatSessie is a Sessie flattened strings.)

  namespace MVC2_NASTEST.Models {

    public partial class FlatSessie {
        public int Ses_ID { get; set; }
        public int Ses_Nummer { get; set; }
        public string Ses_Datum { get; set; }
        public string Ses_Beginuur { get; set; }
        public string Ses_Einduur { get; set; }
        public int Ses_Lpl_ID { get; set; }
        public int Ses_Rks_ID { get; set; }
        public int Ses_LG_ID { get; set; }
    }
  }

so, in my code it goes like this:

                    int antses = m.Mod_AantalSessies.Value;

                    List<List<SelectListItem>> lpllst = new List<List<SelectListItem>>(antses);

                    List<FlatSessie> sl = new List<FlatSessie>(antses);

                    Reeksen rks = _db.Reeksens.First(r => r.Rks_ID == id)

...

List<Sessies> sesl = rks.Sessies.ToList();

                        for (int i = 0; i < antses; i++) {
                            sl.Add(Mapper.Map<Sessies, FlatSessie>(sesl[i]));
                            lpllst.Add(MvcApplication.lesplaatsList(schooljaarparam, sesl[i].Ses_Lpl_ID));
                        }

...

    ViewData["lesplist"] = lpllst;
    ViewData["lglist"] = MvcApplication.lesgeverList();
    return View(sl);

and the lesgeverlist() method

public static List<SelectListItem> lesgeverList() {
            NASDataContext _db = new NASDataContext();
            var lesg = (from l in _db.Lesgevers
                        where l.LG_Naam != "leeg"
                        orderby l.LG_Naam
                        select l).ToSelectList(m => m.LG_Naam + " " + m.LG_Vnaam, m => m.LG_ID.ToString(), m => m.LG_ID < -1);
            return lesg.ToList();
        }

now the problem:

this all works brilliantly. the List goes to the ASPX, i get the form as much times as there are items in the List, and postback works also, the parsing goes and everything. so all is good except for 1 point: the dropdowns.

usually in MVC i don’t set any selected value for a SelectList or for a List because they dont need it, in the Edit page, MVC sets those selected items itself on binding.

now however, with the form in the Foreach loop, all fields get filled besides the dropdown boxes, these do not receive their ‘initial value’.

however when i set an item in the List as selected, it does get selected in the form. (as seen from the ViewData[“lesplist”]) but when i send a normal List with no selected value, the model binder does not propagate it’s given value for that field to the selectedvalue of the dropdown.

however, when i do a form submit, and i return the view (because of validation failed) the dropdowns DO keep their value.

Is this fixable, or is this just a flaw in MVC2?

  • 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-16T11:45:37+00:00Added an answer on May 16, 2026 at 11:45 am

    DropDownListFor not binding on Edit View with repeating items (List<T>)

    there is the answer 🙂

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

Sidebar

Related Questions

If I have an ASP.NET MVC controller action that is called from a jQuery
I have a form action that needs to have its value set from a
I have an action called List that shows the results of a search. It
I have an action like this: public class News : System.Web.Mvc.Controller { public ActionResult
I have an action handling a form post, but I want to make sure
I have an action called EditProfile . To secure it I have added a
I have an action called new : def new @bookmark = Bookmark.new respond_to do
Actually im doing a home page that only have an action called Index() that
My application is in RoR I have an action/view called showsummary where the ID
i have a ApplicationController class with an action called Admin so my url 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.