title: ASP.NET Core Razor Pages - Complex model property is null after returning Page()
body: <p>I'm apparently not understanding something fundamental about model binding complex properties in Razor Pages. When my model isn't valid, I <code>return Page();</code> but I get an exception when referencing a complex property of the model. Here's a slim version of what I have:</p>
  <p>Models:</p>
  <pre><code>public class Movie
  {
      public int Id { get; set; }
      public string Title { get; set; }
      public Director Director { get; set; }
      public string Description { get; set; }
  }
  
  public class Director
  {
      public int Id { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  <p>Index.cshtml.cs:</p>
  <pre><code>[BindProperty]
  public Movie Movie { get; set; }
  
  [BindProperty, Required]
  public string Description { get; set; }
  
  public IActionResult OnGet()
  {
      // Pretend we're loading from the DB...
      Movie = new Movie
      {
          Id = 1,
          Title = &quot;Citizen Kane&quot;,
          Director = new Director
          {
              Id = 101,
              Name = &quot;Orson Wells&quot;
          }
      };
  
      return Page();
  }
  
  public IActionResult OnPost()
  {
      if (!ModelState.IsValid)
          return Page();
  
      Movie.Description = Description;
  
      //Save to DB
      // ...
  
      return RedirectToPage(&quot;/Index&quot;);
  }
  </code></pre>
  <p>Index.cshtml:</p>
  <pre><code>@page
  @model IndexModel
  
  &lt;h5&gt;@Model.Movie.Title&lt;/h5&gt;
  &lt;h6&gt;Directed by @Model.Movie.Director.Name&lt;/h6&gt;
  
  &lt;form method=&quot;post&quot;&gt;
      &lt;div asp-validation-summary=&quot;ModelOnly&quot; class=&quot;text-danger&quot;&gt;&lt;/div&gt;
      &lt;input type=&quot;hidden&quot; asp-for=&quot;Movie.Id&quot; /&gt;
      &lt;textarea asp-for=&quot;Description&quot; placeholder=&quot;Enter Description&quot;&gt;&lt;/textarea&gt;
      &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  <p>When I leave Description blank, the model is invalid in <code>OnPost</code> and returns <code>Page()</code> as expected. But then I get a <code>System.NullReferenceException; Object reference not set to an instance of an object</code> here:</p>
  <pre><code>&lt;h6&gt;Directed by @Model.Movie.Director.Name&lt;/h6&gt;
  </code></pre>
  <p>Why is <code>Movie.Director</code> null here? Do I have to get the data again when returning <code>Page()</code>? I was thinking it would fire <code>OnGet()</code> again but it doesn't. What am I doing wrong?</p>