title: Partial Pages in ASP.NET Core 2.0
body: <p><strong>TL; DR</strong>  Are "partial Pages" possible in ASP.NET Core 2.0?  If so, why am I getting the error described below?</p>
  
  <p>I've been messing with the new <a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/razor-pages/#writing-a-basic-form" rel="nofollow noreferrer">Razor Page</a> feature of ASP.NET 2.0 and having some trouble with partials.  The documentation linked above refers to "partials" in several places, but only to the extent of saying mystical things like "The layouts, templates, and partials you're using with MVC controllers and conventional Razor views <em>just work</em>."  Do they mean <a href="https://docs.microsoft.com/en-us/aspnet/core/mvc/views/partial" rel="nofollow noreferrer">partial Views</a>, like what we're used to, or some new kind of partial Page also?  They show that files with the conventional <code>Partial</code> suffix in the name can be placed in the <code>Pages/</code> folder, but the files that they mention (e.g., <code>_ValidationScriptsPartial.cshtml</code>) don't have the <code>@page</code> declaration.  If "partial Pages" are indeed a new thing, then I would expect the following minimal scenario to work:</p>
  
  <ul>
  <li><p>A Page file named <code>Derp.cshtml</code>:</p>
  
  <pre><code>@page
  @namespace MyApp.Pages
  @model DerpModel
  
  &lt;p&gt;Member 1: @Model.Member1&lt;/p&gt;
  &lt;p&gt;Member 2: @Model.Member2&lt;/p&gt;
  </code></pre></li>
  <li><p>A class file named <code>Derp.cshtml.cs</code> in the same directory (nested under the first in VS 2017's Solution Explorer), containing the following class:  </p>
  
  <pre><code>namespace MyApp.Pages {  
      public class DerpModel : PageModel {
          public void OnGet() {
              Member1 = "Derp Member1";
              Member2 = "Derp Member2";
          }
  
          public string Member1 { get; set; }
          public string Member2 { get; set; }
      }
  }
  </code></pre></li>
  <li><p>A second Page file named <code>DerpWrapper.cshtml</code> in the same directory, with the following code:</p>
  
  <pre><code>@page "{id}"
  @namespace MyApp.Pages
  @model DerpModel
  
  &lt;p&gt;Outer Member 1: @Model.Member1&lt;/p&gt;
  &lt;p&gt;Outer Member 2: @Model.Member2&lt;/p&gt;
  @Html.Partial("Derp", Model)
  </code></pre></li>
  <li><p>And of course a <code>_ViewImports</code> file that declares <code>@namespace MyApp.Pages</code></p></li>
  </ul>
  
  <p>Note that both Razor Pages have the same <code>@model</code> type, and the second Page basically wraps up the first one with a call to <code>Html.Partial()</code> and passes its <code>Model</code>.  This should all be pretty standard stuff, but upon navigating to <code>http://localhost:xxx/DerpWrapper</code>, I get a 500 response due to a NullReferenceException with the following stack trace.  </p>
  
  <pre><code>    MyApp.Pages.Derp_Page.get_Model()
      MyApp.Pages.Derp_Page+&lt;ExecuteAsync&gt;d__0.MoveNext() in Derp.cshtml
      +
      &lt;p&gt;Inner Member1: @Model.Member1&lt;/p&gt;
      ...
      MyApp.Pages.DerpWrapper_Page+&lt;ExecuteAsync&gt;d__0.MoveNext() in DerpWrapper.cshtml
      +
      @Html.Partial("Derp", Model)
      ...
  </code></pre>
  
  <p>Why does the "wrapper" Page's <code>Model</code> equal null?  Is there no way to define a Razor Page and display it from another Page or View with <code>Html.Partial()</code>?</p>