title: C# Razor pages BindProperty attribute not working
body: <p>I'm getting started with my first Razor page and following some examples the <code>[BindProperty]</code> attribute is not working...
  I'm using MongoDB so I'm not using EntityFramework in my project.</p>
  
  <p>Here is my Model class:</p>
  
  <pre><code>public class Student : BaseModel
  {
      public string FirstName;
      public string LastName;
  }
  
  [Serializable]
  public abstract class BaseModel
  {
      [JsonProperty(Order = -2)] // appear first
      [BsonRepresentation(BsonType.ObjectId)]
      public virtual string Id { get; set; }
      [DataType(DataType.DateTime)]
      [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
      public DateTime CreatedDate;
  }
  </code></pre>
  
  <p>Here is my <code>New.cshtml.cs</code> code:</p>
  
  <pre><code>public class NewModel : PageModel
  {
      readonly IStudentsCollection studentsCollection;
      [BindProperty]
      public Student Student { get; set; }
  
  
      public NewModel(IStudentsCollection studentsCollection)
      {
          this.studentsCollection = studentsCollection;
      }
  
      public async Task&lt;IActionResult&gt; OnPostAsync()
      {
          await studentsCollection.InsertAsync(Student);
          return RedirectToPage("Index");
      }
  }
  </code></pre>
  
  <p>And finally, here is my <code>New.cshtml</code> code:</p>
  
  <pre><code>&lt;div class="row"&gt;
      &lt;div class="col-md-4"&gt;
          &lt;form method="post"&gt;
              &lt;h4&gt;Add New Student&lt;/h4&gt;
              &lt;hr /&gt;
              &lt;div asp-validation-summary="All" class="text-danger"&gt;&lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Student.FirstName"&gt;&lt;/label&gt;
                  &lt;input asp-for="Student.FirstName" class="form-control" /&gt;
                  &lt;span asp-validation-for="Student.FirstName" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Student.LastName"&gt;&lt;/label&gt;
                  &lt;input asp-for="Student.LastName" class="form-control" /&gt;
                  &lt;span asp-validation-for="Student.LastName" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;button type="submit" class="btn btn-info"&gt;Save&lt;/button&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Upon clicking the "Save" button I'm getting to the <code>OnPostAsync</code> method but the <code>Student</code> object has all <code>null</code> values...</p>
  
  <p>What am I missing here?</p>