title: Razor Pages models return null for model properties that are classes
body: <p>In my Razor project I have two classes as follows:</p>
  
  <pre><code>namespace reftest.Models
  {
      public class Details
      {
          public int Id { get; set; }
          public int Age { get; set; }
          public int IQ { get; set; }
      }
  
      public class Person
      {
          public int Id { get; set; }
          public string Name { get; set; }
          public Details Particulars { get; set; }
      }
  }
  </code></pre>
  
  <p>I added a Scaffolding Item as per the tutorial which created Create, Delete, Details, Edit and Index pages as usual. These work correctly as far as the Name field is concerned. I can create new Person records, edit them, etc. Age and IQ were not displayed. No problem - I went into the Create.cshtml and added the following:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;label asp-for="Person.Particulars.Age" class="control-label"&gt;&lt;/label&gt;
      &lt;input asp-for="Person.Particulars.Age" class="form-control" /&gt;
      &lt;span asp-validation-for="Person.Particulars.Age" class="text-danger"&gt;&lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>For the corresponding controller I changed nothing but here it is for reference:</p>
  
  <pre><code>public class CreateModel : PageModel
  {
      private readonly reftest.Models.reftestContext _context;
  
      public CreateModel(reftest.Models.reftestContext context)
      {
          _context = context;
      }
  
      public IActionResult OnGet()
      {
          return Page();
      }
  
      [BindProperty]
      public Person Person { get; set; }
  
      public async Task&lt;IActionResult&gt; OnPostAsync()
      {
          if (!ModelState.IsValid)
          {
              return Page();
          }
  
          _context.Person.Add(Person);
          await _context.SaveChangesAsync();
  
          return RedirectToPage("./Index");
      }
  }
  </code></pre>
  
  <p>It displayed a text box for Age and when I entered a value and submitted the new record, it was preserved. I know this by looking at the DB records where I can see a row in the Details table and a corresponding (and correct) Id number for that record in the Particulars column of the Person table.</p>
  
  <p>However, no matter what I do I cannot retrieve it as part of the Person model. The value for Particulars is always Null. For example on the Details page I have this:</p>
  
  <pre><code>&lt;dl class="dl-horizontal"&gt;
      &lt;dt&gt;
          @Html.DisplayNameFor(model =&gt; model.Person.Particulars.Age)
      &lt;/dt&gt;
      &lt;dd&gt;
          @Html.DisplayFor(model =&gt; model.Person.Particulars.Age)
      &lt;/dd&gt;
  &lt;/dl&gt;
  </code></pre>
  
  <p>which always displays an empty field. In the corresponding .cshtml.cs file I have this:</p>
  
  <pre><code>public class DetailsModel : PageModel
  {
      private readonly reftest.Models.reftestContext _context;
  
      public DetailsModel(reftest.Models.reftestContext context)
      {
          _context = context;
      }
  
      public Person Person { get; set; }
  
      public async Task&lt;IActionResult&gt; OnGetAsync(int? id)
      {
          if (id == null)
          {
              return NotFound();
          }
  
          Person = await _context.Person.FirstOrDefaultAsync(m =&gt; m.Id == id);
  
          if (Person == null)
          {
              return NotFound();
          }
          return Page();
      }
  }
  </code></pre>
  
  <p>Person.Particulars is always returned as null. It simply doesn't populate it. But I can see the correct data and foreign key in the database. How can I get it to populate?</p>