title: Razor pages model binding with and without model name
body: <p>I have an ASP.NET 2.0 Razor page intended to implement a contact form. Here is part of the Contact.cshtml file:</p>
  
  <pre class="lang-html prettyprint-override"><code>@page
  @model ContactModel
  &lt;form method="post"&gt;
      &lt;input type="text" asp-for="ContactMessageModel.Name" /&gt;
      &lt;input type="email" asp-for="ContactMessageModel.Email" /&gt;
      &lt;input type="text" asp-for="ContactMessageModel.Message" /&gt;
      &lt;div class="g-recaptcha" data-sitekey="&lt;SiteKey&gt;"&gt;&lt;/div&gt;
      &lt;button type="submit" class="btn btn-primary"&gt;Send&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is part of the Contact.cshtml.cs file:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class ContactModel : PageModel
  {
      [BindProperty]
      public ContactMessageModel ContactMessageModel { get; set; }
  
      public IActionResult OnPostAsync()
      {
          if (!ModelState.IsValid)
          {
              return Page();
          }
  
          return RedirectToPage("MessageSent");
      }
  }
  
  public class ContactMessageModel
  {
      [Required]
      public string Name { get; set; }
  
      [Required]
      public string Email { get; set; }
  
      [Required]
      public string Message { get; set; }
  
      [Required, BindProperty(name="g-recaptcha-response"]
      public string RecaptchaResponse { get; set; }
  }
  </code></pre>
  
  <p>When the form is submitted, the following form data appears in the request:</p>
  
  <pre><code>ContactMessageModel.Name: Fractor
  ContactMessageModel.Email: fractor@example.com
  ContactMessageModel.Message: Hi there!
  g-recaptcha-response: &lt;recaptcha response data&gt;
  </code></pre>
  
  <p>Because the dynamically created <code>g-recaptcha-response</code> form data name does not start with <code>ContactMessageModel</code>, only the Name, Email and Message properties are bound.</p>
  
  <p>I have looked at using <code>[Bind(Prefix = "")]</code> but it looks like I can't apply this to (single) property in the class.</p>
  
  <p>Is there a way of binding to all properties in this model class, despite the different prefixes?</p>