title: How to implement two forms with separate BindProperties in Razor Pages?
body: <p>I am using ASP.NET Core 2 with Razor Pages and I am trying to have <strong>two forms with separate properties (BindProperty) on one page</strong>.</p>
  
  <pre><code>@page
  @model mfa.Web.Pages.TwoFormsModel
  @{
      Layout = null;
  }
  
  &lt;form method="post"&gt;
      &lt;input asp-for="ProductName" /&gt;
      &lt;span asp-validation-for="ProductName" class="text-danger"&gt;&lt;/span&gt;
      &lt;button type="submit" asp-page-handler="Product"&gt;Save product&lt;/button&gt;
  &lt;/form&gt;
  
  &lt;form method="post"&gt;
      &lt;input asp-for="MakerName" /&gt;
      &lt;span asp-validation-for="MakerName" class="text-danger"&gt;&lt;/span&gt;
      &lt;button type="submit" asp-page-handler="Maker"&gt;Save maker&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And the corresponding PageModel:</p>
  
  <pre><code>using Microsoft.AspNetCore.Mvc;
  using Microsoft.AspNetCore.Mvc.RazorPages;
  using System.ComponentModel.DataAnnotations;
  using System.Threading.Tasks;
  
  namespace mfa.Web.Pages
  {
      public class TwoFormsModel : PageModel
      {
          [BindProperty]
          [Required]
          public string ProductName { get; set; }
  
          [BindProperty]
          [Required]
          public string MakerName { get; set; }
  
          public async Task&lt;IActionResult&gt; OnPostProductAsync()
          {
              if (!ModelState.IsValid)
              {
                  return Page();
              }
  
              return Page();
          }
  
          public async Task&lt;IActionResult&gt; OnPostMakerAsync()
          {
              if (!ModelState.IsValid)
              {
                  return Page();
              }
  
              return Page();
          }
      }
  }
  </code></pre>
  
  <p>Hitting any of the two submit buttons brings me in the corresponding post handler. Both "ProdutName" and "MakerName" are populated corectly with whatever I typed in the corresponding input fields. So far, so good.</p>
  
  <p><strong>But</strong>: ModelState.IsValid() <strong>always</strong> returns true - no matter if the value of the corresponding property has a value or not. ModelState.IsValid() is true even when both properties are null.</p>
  
  <p>Also: OnPostProductAsync() should only validate "ProductName" and accordingly OnPostMakerAsync() should only validate "MakerName".</p>
  
  <p>Can this be done at all? Or am I asking too much from Razor Pages? There are plenty of blogs and tutorials that show you how to have two forms on one page ... but they are all using the same model. I need different models! </p>