title: Html.DropDownListFor binding for complex child object
body: <p>I have the following code (ASP.NET MVC/C#)...simplifying some for brevity.</p>
  
  <pre><code>public class UserViewModel
  {
     public int UserId { get; set; }
     public string Name { get; set; }
     public AddressViewModel Address { get; set; }
  
     public IEnumerable&lt;SelectListItem&gt; CitySelectList { get; set; }
  }
  
  public class AddressViewModel
  {
     public int AddressId { get; set; }
     public string StreetAddress { get; set; }
     public int CityId { get; set; }
  }
  </code></pre>
  
  <p>In the razor view I have the following:</p>
  
  <pre><code>@Html.DropDownListFor(x =&gt; x.Address.CityId, Model.CitySelectList)
  </code></pre>
  
  <p>The right city is selected in the dropdown at load time (ie...the original value) so that works fine, but when I submit the form, the CityId property is not updated with the newly selected value....it still contains the original city's id.</p>
  
  <p>I added a new property to the UserViewModel called "SelectedCityId" and bound that to the dropdownlist like this to test the complex nested object being the problem:</p>
  
  <pre><code>@Html.DropDownListFor(x =&gt; x.SelectedCityId, Model.CitySelectList)
  </code></pre>
  
  <p>When I submit the form using this method, the SelectedCityId does contain the right id so I can see model binding working properly when the object is a simple object, but not when it's a nested child object.</p>
  
  <p>Just for troubleshooting, I checked the postal code field as it also binds to a child property of the Address class, but it does bind properly when using the similar TextBoxFor helper:</p>
  
  <pre><code>@Html.TextBoxFor(x =&gt; x.Address.PostalCode)
  </code></pre>
  
  <p>So, my question is why does model binding not seem to work with the DropDownListFor helper when the expression ties the control to a nested child property?  I'm sure its something trivial that I am missing, but I'm not seeing what it is and haven't found a similar answer here.</p>
  
  <p>EDIT:
  Here is the entire html form from the cshtml file</p>
  
  <pre><code>@using (Html.BeginForm("MyProfile", "Account", FormMethod.Post, new { id = "myProfileForm" }))
          {
              @Html.HiddenFor(x =&gt; x.UserId)
              @Html.HiddenFor(x =&gt; x.AddressId)
              @Html.HiddenFor(x =&gt; x.Address.CityId)
  
              &lt;article class="mysettings"&gt;
                  &lt;h1&gt;Personal details&lt;/h1&gt;
                  &lt;table&gt;
                      &lt;tr&gt;
  
  
                  &lt;th&gt;E-mail:&lt;/th&gt;
                      &lt;td&gt;@Model.Username
                          &lt;!--edit fields--&gt;
                          &lt;div class="edit_field" id="field3"&gt;
                              &lt;label for="new_email"&gt;New Email:&lt;/label&gt;
                              @Html.TextBoxFor(x =&gt; x.Username, new { id = "new_email" })
                              &lt;input type="submit" value="save" class="gradient-button" id="submit3"/&gt;
                              &lt;a href="#"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;!--//edit fields--&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;First name:&lt;/th&gt;
                      &lt;td&gt;@Model.FirstName
                          &lt;!--edit fields--&gt;
                          &lt;div class="edit_field" id="field1"&gt;
                              &lt;label for="new_name"&gt;New First Name:&lt;/label&gt;
                              @Html.TextBoxFor(x =&gt; x.FirstName, new { id = "new_name" })
                              &lt;input type="submit" value="save" class="gradient-button" id="submit1"/&gt;
                              &lt;a href="#"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;!--//edit fields--&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;a href="#field1" class="gradient-button edit"&gt;Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Last name:&lt;/th&gt;
                      &lt;td&gt;@Model.LastName
                          &lt;!--edit fields--&gt;
                          &lt;div class="edit_field" id="field2"&gt;
                              &lt;label for="new_last_name"&gt;New Last Name:&lt;/label&gt;
                              @Html.TextBoxFor(x =&gt; x.LastName, new { id = "new_last_name" })
                              &lt;input type="submit" value="save" class="gradient-button" id="submit2"/&gt;
                              &lt;a href="#"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;!--//edit fields--&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;a href="#field2" class="gradient-button edit"&gt;Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Display name:&lt;/th&gt;
                      &lt;td&gt;@Model.DisplayName
                          &lt;!--edit fields--&gt;
                          &lt;div class="edit_field" id="field_display"&gt;
                              &lt;label for="new_display_name"&gt;New Display Name:&lt;/label&gt;
                              @Html.TextBoxFor(x =&gt; x.DisplayName, new { id = "new_display_name" })
                              &lt;input type="submit" value="save" class="gradient-button" id="submit_display"/&gt;
                              &lt;a href="#"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;!--//edit fields--&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;a href="#field_display" class="gradient-button edit"&gt;Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Password:&lt;/th&gt;
                      &lt;td&gt;&lt;input type="password" value="@Model.Membership.Password" disabled="disabled" style="border: none; background-color: white; padding: 0;" /&gt;
                          &lt;!--edit fields--&gt;
                          &lt;div class="edit_field" id="field4"&gt;
                              &lt;label for="new_password"&gt;New Password:&lt;/label&gt;
                              @Html.PasswordFor(x =&gt; x.Membership.Password, new { id = "new_password" })
                              &lt;input type="submit" value="save" class="gradient-button" id="submit4"/&gt;
                              &lt;a href="#"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;!--//edit fields--&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Cell phone:&lt;/th&gt;
                      &lt;td&gt;@Model.CellPhone
                          &lt;!--edit fields--&gt;
                          &lt;div class="edit_field" id="field_cell"&gt;
                              &lt;label for="new_cell"&gt;New Cell Phone:&lt;/label&gt;
                              @Html.TextBoxFor(x =&gt; x.CellPhone, new { id = "new_cell" })
                              &lt;input type="submit" value="save" class="gradient-button" id="submit_cell"/&gt;
                              &lt;a href="#"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;!--//edit fields--&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;a href="#field_cell" class="gradient-button edit"&gt;Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Home phone:&lt;/th&gt;
                      &lt;td&gt;@Model.HomePhone
                          &lt;!--edit fields--&gt;
                          &lt;div class="edit_field" id="field_home"&gt;
                              &lt;label for="new_home"&gt;New Home Phone:&lt;/label&gt;
                              @Html.TextBoxFor(x =&gt; x.HomePhone, new { id = "new_home" })
                              &lt;input type="submit" value="save" class="gradient-button" id="submit_home"/&gt;
                              &lt;a href="#"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;!--//edit fields--&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;a href="#field_home" class="gradient-button edit"&gt;Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Street Address:&lt;/th&gt;
                      &lt;td&gt;@(Model.Address != null ? Model.Address.Address1 : "No address given")
                          &lt;!--edit fields--&gt;
                          &lt;div class="edit_field" id="field5"&gt;
                              &lt;label for="new_address"&gt;New Address:&lt;/label&gt;
                              @Html.TextBoxFor(x =&gt; x.Address.Address1, new { id = "new_address" })
                              &lt;input type="submit" value="save" class="gradient-button" id="submit5"/&gt;
                              &lt;a href="#"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;!--//edit fields--&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;a href="#field5" class="gradient-button edit"&gt;Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;th&gt;Town / City:&lt;/th&gt;
                      &lt;td&gt;@(Model.Address != null ? Model.Address.City.Name : "No address given")
                          &lt;!--edit fields--&gt;
                          &lt;div class="edit_field" id="field6"&gt;
                              &lt;label for="new_city"&gt;New City:&lt;/label&gt;
                              @Html.DropDownListFor(x =&gt; x.Address.CityId, Model.CitySelectList, new { @class = "f-item" })
                              &lt;input type="submit" value="save" class="gradient-button" id="submit6"/&gt;
                              &lt;a href="#"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;!--//edit fields--&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;a href="#field6" class="gradient-button edit"&gt;Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;th&gt;Postal Code:&lt;/th&gt;
                      &lt;td&gt;@(Model.Address != null ? Model.Address.PostalCode : "No address given")
                          &lt;!--edit fields--&gt;
                          &lt;div class="edit_field" id="field7"&gt;
                              &lt;label for="new_zip"&gt;New Postal Code:&lt;/label&gt;
                              @Html.TextBoxFor(x =&gt; x.Address.PostalCode, new { id = "new_zip" })
                              &lt;input type="submit" value="save" class="gradient-button" id="submit7"/&gt;
                              &lt;a href="#"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;!--//edit fields--&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;a href="#field7" class="gradient-button edit"&gt;Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;th&gt;First Admin Division (State):&lt;/th&gt;
                      &lt;td&gt;@(Model.Address != null ? Model.Address.City.FirstAdminDivision.Name : "No address given")
                          &lt;!--edit fields--&gt;
                          &lt;div class="edit_field" id="field8"&gt;
                              &lt;label for="new_state"&gt;New First Admin Division (State):&lt;/label&gt;
                              &lt;input type="text" id="new_state"/&gt;
                              &lt;input type="submit" value="save" class="gradient-button" id="submit8"/&gt;
                              &lt;a href="#"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;!--//edit fields--&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;a href="#field8" class="gradient-button edit"&gt;Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;th&gt;Country:&lt;/th&gt;
                      &lt;td&gt;@(Model.Address != null ? Model.Address.City.FirstAdminDivision.Country.Name : "No address given")
                          &lt;!--edit fields--&gt;
                          &lt;div class="edit_field" id="field9"&gt;
                              &lt;label for="new_country"&gt;New Country:&lt;/label&gt;
                              &lt;input type="text" id="new_country"/&gt;
                              &lt;input type="submit" value="save" class="gradient-button" id="submit9"/&gt;
                              &lt;a href="#"&gt;Cancel&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;!--//edit fields--&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;a href="#field8" class="gradient-button edit"&gt;Edit&lt;/a&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
  
          &lt;/article&gt;
      }
  </code></pre>
  
  <p>And the two controller actions:</p>
  
  <pre><code>public ActionResult MyProfile()
          {
              IAccountService accountSvc = GetService&lt;IAccountService&gt;();
              UserProfileServiceRequest request = new UserProfileServiceRequest();
  
              int userId = int.Parse(SessionMgr.GetInstance().GetSessionValue(SessionTypes.UserId).ToString());
  
              if (userId == 0)
              {
                  return RedirectToAction("Login", "Account");
              }
              else
              {
                  request.UserId = userId;
                  UserProfileServiceResponse response = accountSvc.GetUserProfile(request);
                  UserProfileViewModel model = AutoMapper.Mapper.Map&lt;UserProfileViewModel&gt;(response.UserProfile);
  
                  ICommonService commonSvc = GetService&lt;ICommonService&gt;();
                  GetCitiesServiceRequest citiesRequest = new GetCitiesServiceRequest { FirstAdminDivisionId = model.Address.City.FirstAdminDivision.FirstAdminDivisionId };
                  KeyValuePairServiceResponse citiesResponse = commonSvc.GetCitiesForSelect(citiesRequest);
                  model.CitySelectList = citiesResponse.KeyValuePairs.ToSelectList();
  
                  List&lt;RoleViewModel&gt; roles = (List&lt;RoleViewModel&gt;)SessionMgr.GetInstance().GetSessionValue(SessionTypes.Roles);
                  RoleViewModel consumerRole = roles.FirstOrDefault(x =&gt; x.Meaning.Equals(DataEnumerations.GetRoleMeaning(DataEnumerations.Role.Consumer)));
  
                  if (consumerRole != null)
                  {
                      GetConsumerTripsServiceRequest consumerTripsRequest = new GetConsumerTripsServiceRequest() { UserId = userId };
                      GetConsumerTripsServiceResponse consumerTripsResponse = commonSvc.GetConsumerTrips(consumerTripsRequest);
                      model.ConsumerTrips = AutoMapper.Mapper.Map&lt;List&lt;TripViewModel&gt;&gt;(consumerTripsResponse.Trips);
  
                      GetUserReviewsServiceRequest userReviewsRequest = new GetUserReviewsServiceRequest() { UserId = userId };
                      GetUserReviewsServiceResponse userReviewsResponse = commonSvc.GetUserReviews(userReviewsRequest);
                      model.UserReviews = AutoMapper.Mapper.Map&lt;List&lt;UserReviewViewModel&gt;&gt;(userReviewsResponse.UserReviews);
                  }
  
                  return View(model);
              }
          }
  
  [HttpPost]
          public ActionResult MyProfile(UserProfileViewModel model)
          {
              UpdateUserProfileServiceRequest request = AutoMapper.Mapper.Map&lt;UpdateUserProfileServiceRequest&gt;(model);
  
              IAccountService accountSvc = GetService&lt;IAccountService&gt;();
              accountSvc.UpdateUserProfile(request);
  
              return RedirectToAction("MyProfile", "Account");
  
          }
  </code></pre>
  
  <p>The entire AddressViewModel class:</p>
  
  <pre><code>public class AddressViewModel
      {
          public Int32 AddressId { get; set; }
          public String Address1 { get; set; }
          public String Address2 { get; set; }
          public Int32 CityId { get; set; }
          public String PostalCode { get; set; }
  
          public CityViewModel City { get; set; }
  
      }
  </code></pre>
  
  <p>And the entire UserProfileViewModel:</p>
  
  <pre><code>public class UserProfileViewModel : BaseViewModel
      {
          public int UserId { get; set; }
          public string Username { get; set; }
          public string FirstName { get; set; }
          public string LastName { get; set; }
          public string DisplayName { get; set; }
          public string CellPhone { get; set; }
          public string HomePhone { get; set; }
          public int AddressId { get; set; }
  
          public AddressViewModel Address { get; set; }
          public MembershipViewModel Membership { get; set; }
  
          public List&lt;TripViewModel&gt; ConsumerTrips { get; set; }
  
          public List&lt;UserReviewViewModel&gt; UserReviews { get; set; }
  
          public IEnumerable&lt;SelectListItem&gt; CitySelectList { get; set; }
          public int SelectedCityId { get; set; }
      }
  </code></pre>