title: How to post view model to controller
body: <p>I am trying to create a view that takes a view model, simply has an int property and a list of child model, with int; string; string properties.</p>
  
  <p>What i am trying to do is everytime user clicks an "add line" button, i am creating a new child model in my view model list, letting user edit the properties and then want to post back to my controller but no matter what, it is always empty.</p>
  
  <p>I know this must be simple but has me stumped for hours today? Is there some magic that needs to happen?</p>
  
  <p>Any help appreciated.</p>
  
  <p>My Controller:</p>
  
  <pre><code>using System.Web.Mvc;
  using WebApplication1.Models;
  
  namespace WebApplication1.Controllers
  {
      public class EmployeeUploadController : Controller
      {
          // GET: EmployeeUpload
          public ActionResult EmployeeUpload()
          {
              var vm = new EmployeeBulkUpload { UploadedBy = 12345 };
              vm.Employees.Add(new EmployeeBulkUploadItem { Id = 1, JobTitle = "Labourer", Name = "Jimmy" });
              return View(vm);
          }
  
          [HttpPost]
          [ActionName("EmployeeUpload")]
          public ActionResult EmployeeUploadPost(EmployeeBulkUpload vm)
          {
  
              return View(vm);
          }
      }
  }
  </code></pre>
  
  <p>My Model:</p>
  
  <pre><code>using System.Collections.Generic;
  
  namespace WebApplication1.Models
  {
      public class EmployeeBulkUpload
      {
          public EmployeeBulkUpload()
          {
              Employees = new List&lt;EmployeeBulkUploadItem&gt;();
          }
          public int UploadedBy { get; set; }
          public List&lt;EmployeeBulkUploadItem&gt; Employees { get; set; }
      }
  
      public class EmployeeBulkUploadItem
      {
          public int Id { get; set; }
          public string Name { get; set; }
          public string JobTitle { get; set; }
      }
  } 
  </code></pre>
  
  <p>My "Container" view:</p>
  
  <pre><code>@using WebApplication1.Models
  @model WebApplication1.Models.EmployeeBulkUpload
  @{
      ViewBag.Title = "EmployeeUpload";
  }&lt;div&gt;
      @using (Html.BeginForm("EmployeeUpload", "EmployeeUpload", FormMethod.Post))
      {
      &lt;h2&gt;EmployeeUpload&lt;/h2&gt;
      &lt;button&gt;Add New&lt;/button&gt;
  
      foreach(EmployeeBulkUploadItem emp in Model.Employees)
      {
          Html.RenderPartial("_EmployeeUploadItem", emp);
      }
  
      &lt;input type="submit" name="SaveButton" value="Save" /&gt;
      }
  &lt;/div&gt;
  </code></pre>
  
  <p>My Item Partial view:</p>
  
  <pre><code>@model WebApplication1.Models.EmployeeBulkUploadItem
  &lt;li&gt;
      @Html.LabelFor(x =&gt; x.Id)
      @Html.EditorFor(x =&gt; x.Id)
      @Html.LabelFor(x =&gt; x.Name)
      @Html.EditorFor(x =&gt; x.Name)
      @Html.LabelFor(x =&gt; x.JobTitle)
      @Html.EditorFor(x =&gt; x.JobTitle)
  &lt;/li&gt;
  </code></pre>
  
  <p>I can load with one record and post straight back but is always empty in my Controller EmployeeUploadPost method?</p>