title: Unable to pass Model from View to Controller.
body: <p>I actually get the <code>Model</code> in <code>Http Request</code>. But it is not getting loaded in controller.</p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class ConfigurableItemsModel 
  {
     public IList&lt;State&gt; State { get; set; }
     public IList&lt;Country&gt; Country { get; set; }
     public IList&lt;AccountType&gt; AccountTypes { get; set; }
     public IList&lt;AddressSource&gt; AddressSources { get; set; }
     public IList&lt;StopCode&gt; StopCodes { get; set; }
  
     public State state { get; set; }
     public Country country { get; set; }
     public AccountType accountType { get; set; }
     public AddressSource addressSource { get; set; }
     public StopCode stopCode { get; set; }     
   }
  </code></pre>
  
  <p><strong>Controller Method (Get)</strong>   </p>
  
  <pre><code>public ActionResult Edit(string ConfigName)
  {
    ConfigurableItemsClient client = new ConfigurableItemsClient();
    ConfigurableItemsModel configItemsModel = new ConfigurableItemsModel();
    List&lt;ConfigurableItemsModel&gt; configItemsModelList = new List&lt;ConfigurableItemsModel&gt;();
  
     switch (ConfigName)
     {
                  case "Country":
                      List&lt;Country&gt; countryList = new List&lt;Country&gt;();                   
                      countryList = client.GetAllCountries().ToList();
  
                      int count = countryList.Count;
  
                      for (int i = 0; i &lt; count; i++)
                      {
                          configItemsModel.Country = new List&lt;Country&gt;();
                          configItemsModel.Country = countryList;
                      }
                      configItemsModelList.Add(configItemsModel);
                      TempData["temporaryCountry"] = configItemsModel;
                      ViewBag.NoOfTimes = count;
                      ViewBag.ConfigItem = "Country";
                      return View(configItemsModelList);
                      break;
                  case "State":
                      List&lt;State&gt; stateList = new List&lt;State&gt;();
                      stateList = client.GetAllStates().ToList();  
                      configItemsModelList.Clear();
  
                      for (int i = 0; i &lt; stateList.Count; i++)
                      {
                          configItemsModel.State = new List&lt;State&gt;();
                          configItemsModel.State = stateList;
                      }
                      configItemsModelList.Add(configItemsModel);
                      ViewBag.NoOfTimes = stateList.Count;
                      ViewBag.ConfigItem = "State";
                      return View(configItemsModelList);
                      break;
                  case "Account Type":
                      List&lt;AccountType&gt; accountTypeList = new List&lt;AccountType&gt;();
                      accountTypeList = client.GetAllAccountType().ToList();
                      configItemsModelList.Clear();
                      for (int i = 0; i &lt; accountTypeList.Count; i++)
                      {
                          configItemsModel.AccountTypes = new List&lt;AccountType&gt;();
                          configItemsModel.AccountTypes = accountTypeList;
                      }
                      configItemsModelList.Add(configItemsModel);
                      ViewBag.NoOfTimes = accountTypeList.Count;
                      ViewBag.ConfigItem = "AccountType";
                      return View(configItemsModelList);
                      break;
                  case "Stop Code" :
                      List&lt;StopCode&gt; stopCodeList = new List&lt;StopCode&gt;();
                      stopCodeList = client.GetAllStopCodes().ToList();
                     configItemsModelList.Clear();
                     for (int i = 0; i &lt; stopCodeList.Count; i++)
                      {
                          configItemsModel.StopCodes = new List&lt;StopCode&gt;();
                          configItemsModel.StopCodes = stopCodeList;
                      }
                      configItemsModelList.Add(configItemsModel);
                      ViewBag.NoOfTimes = stopCodeList.Count;
                      ViewBag.ConfigItem = "StopCode";
                      return View(configItemsModelList);
                      break;
                  case "Address Source":
                      List&lt;AddressSource&gt; addressSourceList = new List&lt;AddressSource&gt;();
                      addressSourceList = client.GetAllAddressSources().ToList();
                      configItemsModelList.Clear();
                      for (int i = 0; i &lt; addressSourceList.Count; i++)
                      {
                          configItemsModel.AddressSources = new List&lt;AddressSource&gt;();
                          configItemsModel.AddressSources = addressSourceList;
                      }
                      configItemsModelList.Add(configItemsModel);
                      ViewBag.NoOfTimes = addressSourceList.Count;
                      ViewBag.ConfigItem = "AddressSource";
                      return View(configItemsModelList);
                      break;
              }
  
     return View(); 
  }
  </code></pre>
  
  <p><strong>Controller Method (Post)</strong>      </p>
  
  <pre><code>[HttpPost]
  public ActionResult Edit(ConfigurableItemsModel modelFromView, string EditViewButton)
  {
              ConfigurableItemsClient client = new ConfigurableItemsClient();
              switch (EditViewButton)
              {
                  case "Add":
                      return View();
                      break;
                  case "Edit":
                      return View();
                      break;
                  case "Save":
                      //if(ViewBag.ConfigItem == "Country")
                      //{
  
                          int i = 0;
                          Country NewCountry = new Country();
                          NewCountry.CountryId = modelFromView.Country[i].CountryId;
                          NewCountry.CountryCode = modelFromView.Country[i].CountryCode;
                          NewCountry.CountryName = modelFromView.Country[i].CountryName;
                          NewCountry.WorkStationId = 1;
                          NewCountry.CreatedBy = 1;
                          NewCountry.CreatedOn = DateTime.Now;
                          NewCountry.ModifiedBy = 1;
                          NewCountry.ModifiedOn = DateTime.Now;
                          client.AddNewCountry(NewCountry);
                      //}
                      return View(modelFromView.Country);
                      break;
              }
              return View();
   }       
  </code></pre>
  
  <p><strong>View Page</strong></p>
  
  <pre><code>@model IEnumerable&lt;Models.ConfigurableItemsModel&gt;
  @{
      ViewBag.Title = "Edit";
  }
  
  @using (Html.BeginForm())
  {
      @Html.ValidationSummary(true)
      &lt;fieldset&gt;
          &lt;legend&gt;Country&lt;/legend&gt;
          @if (ViewBag.ConfigItem == "Country")
          {
              &lt;h2&gt;Country&lt;/h2&gt;
              int k = 0;
  
  
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;th&gt;
                          &lt;label&gt;Select&lt;/label&gt;
                      &lt;/th&gt;
                      &lt;th&gt;
                          @Html.DisplayNameFor(model =&gt; model.Country[k].CountryId)
                      &lt;/th&gt;
                      &lt;th&gt;
                          @Html.DisplayNameFor(model =&gt; model.Country[k].CountryName)
                      &lt;/th&gt;
                      &lt;th&gt;
                          @Html.DisplayNameFor(model =&gt; model.Country[k].CountryCode)
                      &lt;/th&gt;
                  &lt;/tr&gt;
  
                  @foreach (var item in Model)
                  {
                      for (int j = 0; j &lt; item.Country.Count; j++)
                      {
  
                      &lt;tr&gt;
                          &lt;th&gt;
                              &lt;input type="checkbox" name="chkCountry" /&gt;&lt;/th&gt;
                          &lt;th&gt;
                              @Html.EditorFor(model =&gt; item.Country[j].CountryId)
                          &lt;/th&gt;
                          &lt;th&gt;
                              @Html.EditorFor(model =&gt; item.Country[j].CountryName)
                          &lt;/th&gt;
                          &lt;th&gt;
  
                              @Html.EditorFor(model =&gt; item.Country[j].CountryCode)
                          &lt;/th&gt;
                      &lt;/tr&gt;
  
                      }
  
                  }
  
              &lt;/table&gt;   
              &lt;input type="submit" value="Save" name="EditViewButton" /&gt; 
  
          }
      &lt;/fieldset&gt;
  }
  
  @if (ViewBag.ConfigItem == "State")
  {
      &lt;h2&gt;State&lt;/h2&gt;
      int k = 0;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  &lt;label&gt;Select&lt;/label&gt;
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.State[k].StateId)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.State[k].CountryId)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.State[k].StateName)
              &lt;/th&gt;
          &lt;/tr&gt;
  
          @foreach (var item in Model)
          {
              for (int i = 0; i &lt; ViewBag.NoOfTimes; i++)
              {
              &lt;tr&gt;
                  &lt;th&gt;
                      &lt;input type="checkbox" name="chkState" /&gt;&lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.State[i].StateId)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.State[i].CountryId)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.State[i].StateName)
                  &lt;/th&gt;
              &lt;/tr&gt;
              }
          }
      &lt;/table&gt;             
  
  }
  
  @if (ViewBag.ConfigItem == "AddressSource")
  {
      &lt;h2&gt;Address Source&lt;/h2&gt;
      int k = 0;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  &lt;label&gt;Select&lt;/label&gt;
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.AddressSources[k].Value)
  
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.AddressSources[k].ValueDescription)
  
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.AddressSources[k].DisplayOrder)
  
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.AddressSources[k].IsActive)
  
              &lt;/th&gt;
          &lt;/tr&gt;
  
          @foreach (var item in Model)
          {
              for (int i = 0; i &lt; ViewBag.NoOfTimes; i++)
              {
              &lt;tr&gt;
                  &lt;th&gt;
                      &lt;input type="checkbox" name="chkAddressSource" /&gt;&lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.AddressSources[i].Value)
                      @Html.HiddenFor(model =&gt; item.AddressSources[i].Value)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.AddressSources[i].ValueDescription)
                      @Html.HiddenFor(model =&gt; item.AddressSources[i].ValueDescription)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.AddressSources[i].DisplayOrder)
                      @Html.HiddenFor(model =&gt; item.AddressSources[i].DisplayOrder)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.AddressSources[i].IsActive)
                      @Html.HiddenFor(model =&gt; item.AddressSources[i].IsActive)
                  &lt;/th&gt;
              &lt;/tr&gt;
              }
          }
      &lt;/table&gt;             
  
  }
  
  @if (ViewBag.ConfigItem == "AccountType")
  {
      &lt;h2&gt;Account Type&lt;/h2&gt;
      int k = 0;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  &lt;label&gt;Select&lt;/label&gt;
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.AccountTypes[k].Value)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.AccountTypes[k].ValueDescription)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.AccountTypes[k].DisplayOrder)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.AccountTypes[k].IsActive)
              &lt;/th&gt;
          &lt;/tr&gt;
  
          @foreach (var item in Model)
          {
              for (int i = 0; i &lt; ViewBag.NoOfTimes; i++)
              {
              &lt;tr&gt;
                  &lt;th&gt;
                      &lt;input type="checkbox" name="chkAccountType" /&gt;&lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.AccountTypes[i].Value)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.AccountTypes[i].ValueDescription)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.AccountTypes[i].DisplayOrder)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.AccountTypes[i].IsActive)
                  &lt;/th&gt;
              &lt;/tr&gt;
              }
          }
      &lt;/table&gt;             
  
  }
  
  @if (ViewBag.ConfigItem == "StopCode")
  {
      &lt;h2&gt;Stop Code&lt;/h2&gt;
      int k = 0;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  &lt;label&gt;Select&lt;/label&gt;
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.StopCodes[k].Code)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.StopCodes[k].StopCodeName)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.StopCodes[k].StopCodeDescription)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.StopCodes[k].IsActive)
              &lt;/th&gt;
          &lt;/tr&gt;
  
          @foreach (var item in Model)
          {
              for (int i = 0; i &lt; ViewBag.NoOfTimes; i++)
              {
              &lt;tr&gt;
                  &lt;th&gt;
                      &lt;input type="checkbox" name="chkStopCode" /&gt;&lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.StopCodes[i].Code)
                      @Html.EditorFor(model =&gt; item.StopCodes[i].Code)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.StopCodes[i].StopCodeName)
                      @Html.EditorFor(model =&gt; item.StopCodes[i].StopCodeName)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.StopCodes[i].StopCodeDescription)
                      @Html.EditorFor(model =&gt; item.StopCodes[i].StopCodeDescription)
                  &lt;/th&gt;
                  &lt;th&gt;
                      @Html.DisplayFor(model =&gt; item.StopCodes[i].IsActive)
                      @Html.EditorFor(model =&gt; item.StopCodes[i].IsActive)
                  &lt;/th&gt;
              &lt;/tr&gt;
              }
          }
      &lt;/table&gt;             
  
  }
  
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;                
                  &lt;input type="submit" value="Delete" name="EditViewButton" /&gt;          
          &lt;/th&gt;
          &lt;th&gt;                  
                  &lt;input type="submit" value="De-Activate" name="EditViewButton" /&gt;           
          &lt;/th&gt;
          &lt;th&gt;
              @using (Html.BeginForm("Index", "ConfigurableItems", FormMethod.Get))
              {
                  &lt;input type="submit" value="Cancel" /&gt;
              }
          &lt;/th&gt;
          &lt;th&gt;                 
                  &lt;input type="submit" value="Add" name="EditViewButton" /&gt;          
          &lt;/th&gt;
          &lt;th&gt;                 
                  &lt;input type="submit" value="Edit" name="EditViewButton" /&gt;            
          &lt;/th&gt;
          &lt;th&gt;                 
                  &lt;input type="submit" value="Save" name="EditViewButton" /&gt;           
          &lt;/th&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  
  @section Scripts {
      @Scripts.Render("~/bundles/jqueryval")
  }
  </code></pre>
  
  <p>When I click on <code>Save</code> button present under Country, I am able to see that Country related values and <code>EditViewButton</code> is getting passed in request but it is not appearing in Controller action HTTPPOST <code>Edit</code> method. </p>
  
  <p>I am stuck with this problem for two days and google did not help much. Appreciate your help in this.</p>