title: How to get data from a partial view ViewModel in to the main ViewModel
body: <p>I am creating a POC application using ASP.net MVC5. I want to have a top level view model that contains the data for all the view models in the partial views. However when I submit the form it doesn't pass data in the models to the top level which I somewhat expected but didn't want to happen.</p>
  
  <p>View models</p>
  
  <pre class="lang-C# prettyprint-override"><code>public class InvoiceViewModel
  {
      public InvoiceInfo InvoiceInfo { get; set; }
  }
  
  public class InvoiceInfo
  {
      [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
      public DateTime DateRaised { get; set; } = DateTime.Now;
      public int InvoiceNo { get; set; }
      public DateTime FromDate { get; set; }
      public DateTime ToDate { get; set; }
      public Currency InvoiceCurrency { get; set; }
  }
  </code></pre>
  
  <p>Form submit function</p>
  
  <pre><code>[HttpPost]
  public ActionResult CreateInvoice(InvoiceInfo vm)
  {
      if (ModelState.IsValid)
      {
          vm.FromDate = vm.ToDate;
      }
  
      return View(vm);
  }
  </code></pre>
  
  <p>Main razer view using 'InvoiceViewModel'</p>
  
  <pre><code>@using (Html.BeginForm("CreateInvoice", "Invoice", FormMethod.Post))
  {
      @Html.AntiForgeryToken()
  
      &lt;div class="form-horizontal"&gt;
          &lt;hr /&gt;
          @Html.Partial("_InvoiceInfo", Model.InvoiceInfo)
  
          &lt;div class="form-group"&gt;
              &lt;div class="col-md-offset-2 col-md-10"&gt;
                  &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }
  </code></pre>
  
  <p>Partial view '_InvoiceInfo'</p>
  
  <pre><code>&lt;div class="form-horizontal"&gt;
      &lt;h4&gt;InvoiceInfo&lt;/h4&gt;
      &lt;hr /&gt;
      @Html.ValidationSummary(true, "", new { @class = "text-danger" })
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.DateRaised, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.DateRaised, new { htmlAttributes = new { @class = "form-control datepicker" } })
              @Html.ValidationMessageFor(model =&gt; model.DateRaised, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.InvoiceNo, htmlAttributes: new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.InvoiceNo, new { htmlAttributes = new { @class = "form-control" } })
              @Html.ValidationMessageFor(model =&gt; model.InvoiceNo, "", new { @class = "text-danger" })
          &lt;/div&gt;
      &lt;/div&gt;
  ETC...
  </code></pre>
  
  <p>So When I click submit I would expect the InvoiceInfo object to be within the InvoiceViewModel object with all the relevant data. This might not be possible but any help would be appreciated.</p>