title: Why are the PartialView models null in a PostBack to an Asp.Net Core Razor main page view's controller?
body: <p>I have an Asp.Net Core Razor page that contains several partial views.
  On the post back to the main page controller, I am getting nulls for my partial view models.</p>
  <p>How do I ensure that these getting correctly populated and sent as part of the main view model
  to my controller?</p>
  <p>Below is a simplified example.
  <strong>Here are my model definitions:</strong></p>
  <pre><code>public class MainPageViewModel
  {
      public string DocumentName { get; set; }
      public string DocumentNumber { get; set; }
      public string ViewName { get; set; }
      public PartialSampleViewModel PartialSampleModel { get; set; }
  
  }
  
  public class PartialSampleViewModel
  {
      public DateTime DetailsDate { get; set; }
      public String DetailsDescription { get; set; }
  }
  </code></pre>
  <p><strong>Here is my controller definition:</strong></p>
  <pre><code>public class MainPageController : Controller
  {
      public async Task&lt;IActionResult&gt; Index()
      {
          var viewModel = new MainPageViewModel()
          {
              DocumentName = &quot;Foo&quot;,
              DocumentNumber = &quot;1&quot;,
              PartialSampleModel = new PartialSampleViewModel()
              {
                  DetalsDate = DateTime.Now,
                  DetailsDescription = &quot;Description&quot;
              }
          };
  
          return View(viewModel);
      }
  
      [HttpPost]
      public async Task&lt;IActionResult&gt; SaveDocument(MainPageViewModel mainPageViewModel)
      {
          // mainPageViewModel.PartialSampleModel is null.
      }
  }
  </code></pre>
  <p><strong>Here is my main page definition:</strong></p>
  <pre><code>@model MainPageViewModel
  
  &lt;form method=&quot;post&quot; action=&quot;SaveDocument&quot; &gt;
      &lt;div id=&quot;InputFormPanel&quot; class=&quot;InputFormPanel&quot;&gt;
          &lt;partial name=&quot;@Model.ViewName&quot; model=&quot;@Model.PartialSampleModel&quot; /&gt;
      &lt;/div&gt;
          
      &lt;div class=&quot;col-md-2&quot;&gt;
          &lt;label asp-for=&quot;DocumentName&quot;&gt;Document Name:&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class=&quot;col-md-4&quot;&gt;
          &lt;input class=&quot;form-control&quot; asp-for=&quot;DocumentName&quot; /&gt;
          &lt;span asp-validation-for=&quot;DocumentName&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
      &lt;/div&gt;
      &lt;div class=&quot;col-md-1&quot;&gt;
          &lt;label asp-for=&quot;DocumentNumber&quot;&gt;Number:&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class=&quot;col-md-2&quot;&gt;
          &lt;input class=&quot;form-control&quot; asp-for=&quot;DocumentNumber&quot; /&gt;
      &lt;/div&gt;  
  
      &lt;!-- A bunch more common fields on main page --&gt;
      &lt;div class=&quot;text-center panel-body&quot;&gt;
          &lt;button id=&quot;SaveButton&quot; class=&quot;btn btn-sm btn-primary ApproveDocument&quot; &gt;Save Form&lt;/button&gt;
      &lt;/div&gt;  
  &lt;/form&gt;
  </code></pre>
  <p><strong>Here is my partial view definition:</strong></p>
  <pre><code>@model PartialSampleModelRecord
  
  &lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;col-md-6&quot;&gt;
          &lt;label asp-for=&quot;DetailsDate&quot;&gt;Date:: &lt;/label&gt;&lt;/td&gt;
      &lt;/div&gt;
      &lt;div class=&quot;col-md-6&quot;&gt;
          &lt;input class=&quot;form-control&quot; asp-for=&quot;DetailsDate&quot; /&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;col-md-6&quot;&gt;
          &lt;label asp-for=&quot;DetailsDescription&quot;&gt;Description:&lt;/label&gt;
      &lt;/div&gt;
      &lt;div class=&quot;col-md-6&quot;&gt;
          &lt;input class=&quot;form-control&quot; asp-for=&quot;DetailsDescription&quot; /&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- A bunch more other fields --&gt;
  </code></pre>
  <p>Does the issue lie with my model definitions or with the definition of my PartialView(s)?</p>