title: MVC4 - Partial View Model binding during Submit
body: <p>I have view model which has another child model to render the partial view (below).</p>
  
  <pre><code>public class ExamResultsFormViewModel
  {
      public PreliminaryInformationViewModel PreliminaryInformation { get; set; }
  
      public string MemberID { get; set; }
  
      public string MemberName { get; set; }
  
      public int PatientID { get; set; }
  
      public string ConfirmationID { get; set; }
  
      public bool IsEditable { get; set; }
  
      #region Select Lists
      public SelectList ProviderOptions { get; set; }
      #endregion
  }
  
  public class PreliminaryInformationViewModel
  {
      public string ProviderName { get; set; }
  
      public string ProviderID { get; set; }
  
      public string ServiceLocation { get; set; }
  }
  </code></pre>
  
  <p>This PreliminaryInformationViewModel view model also used as a child models in another view model since this preliminary information can be updated at different pages.</p>
  
  <p>So I created this preliminary information as a separate partial and to include in other pages.</p>
  
  <pre><code>@{Html.RenderPartial("_PreliminaryInformation", Model.PreliminaryInformation);}
  </code></pre>
  
  <p>Inside the partial</p>
  
  <pre><code>@model Web.Models.Preliminary.PreliminaryInformationViewModel
  &lt;div&gt;
      @Html.TextBoxFor(x =&gt; x.DateOfService })
  &lt;/div&gt;
  </code></pre>
  
  <p>But the problem is during submit this preliminary model is always null due to the reason HTML name attribute is always is rendered as
  </p>
  
  <p>but when I pass the parent model to the partial as below.</p>
  
  <pre><code>@model Web.Models.Exam.ExamResultsFormViewModel
  &lt;div&gt;
      @Html.TextBoxFor(x =&gt; x.PreliminaryInformation.DateOfService })
  &lt;/div&gt;
  </code></pre>
  
  <p>Now the HTML element is generated as</p>
  
  <pre><code>&lt;input type = 'text' name='PreliminaryInformation.DateOfService.DateOfService' id='PreliminaryInformation.DateOfService'&gt;
  </code></pre>
  
  <p>and it binds properly during the submit.</p>
  
  <p>I understand MVC bind the element value based on the name attribute value, but the second implementation would need me to create a multiple partial for each page, which I don't like.</p>
  
  <p>So far I couldn't find a solution to work with the first implementation, is there way I can make preliminary information model value bind during submit with the first implementation.</p>