title: Multiple Forms with multiple Models - OnPost Model is null
body: <p>Added the handler, I can call the correct method, but my model is always null. I'm sure i'm not assigning the model correctly. I am sending 3 models to the form to populate the tables for check box permission selection. When I click the save button, the model is blank. I do prefer 1 save button but tried to assign base previledges to the 1 button, and other employee and user tables the remaining buttons.</p>
  <pre><code>@page
  @model MosaicTitlePro.Pages.User.RolesPermissionsModel
  @{
      ViewData[&quot;Title&quot;] = &quot;Modify Permissions for &quot;;
      Layout = &quot;~/Pages/Shared/Mosaic/_Layout.cshtml&quot;;
  }
  &lt;div class=&quot;container&quot;&gt;
      &lt;h3&gt;Modify Permissions for Role: @Model.basePermissions.RoleName&lt;/h3&gt;
      &lt;hr /&gt;
      &lt;h4&gt;Base Permissions &lt;/h4&gt;
      &lt;form method=&quot;post&quot; asp-page-handler=&quot;base&quot; enctype=&quot;multipart/form-data&quot;&gt;
          &lt;input asp-for=&quot;@Model.basePermissions.RoleId&quot; type=&quot;hidden&quot; /&gt;
          &lt;table class=&quot;table table-striped&quot; id=&quot;permissionTable&quot;&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;
                          Type
                      &lt;/th&gt;
                      &lt;th&gt;
                          Permission
                      &lt;/th&gt;
                      &lt;th&gt;
                          Status
                      &lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
  
                  @for (int i = 0; i &lt; Model.basePermissions.RoleClaims.Count(); i++)
                  {
                      &lt;tr&gt;
                          &lt;td&gt;
                              &lt;input asp-for=&quot;@Model.basePermissions.RoleClaims[i].Type&quot; type=&quot;hidden&quot; /&gt;
                              @Model.basePermissions.RoleClaims[i].Type
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;input asp-for=&quot;@Model.basePermissions.RoleClaims[i].Value&quot; type=&quot;hidden&quot; /&gt;
                              @Model.basePermissions.RoleClaims[i].Value
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;div class=&quot;form-check m-1&quot;&gt;
                                  &lt;input asp-for=&quot;@Model.basePermissions.RoleClaims[i].Selected&quot; class=&quot;form-check-input&quot; /&gt;
                              &lt;/div&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  }
              &lt;/tbody&gt;
          &lt;/table&gt;
          &lt;button type=&quot;submit&quot; id=&quot;save&quot; class=&quot;btn bg-primary&quot;&gt;
              &lt;i class=&quot;fa fa-check&quot;&gt;&lt;/i&gt;
              Save
          &lt;/button&gt;
  
      &lt;/form&gt;
  
      &lt;h4&gt;HR Permissions &lt;/h4&gt;
      &lt;table class=&quot;table table-striped&quot; id=&quot;permissionTable&quot;&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      Type
                  &lt;/th&gt;
                  &lt;th&gt;
                      Permission
                  &lt;/th&gt;
                  &lt;th&gt;
                      Status
                  &lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
  
              @for (int i = 0; i &lt; Model.employeePermissions.RoleClaims.Count(); i++)
              {
                  &lt;tr&gt;
                      &lt;td&gt;
                          &lt;input asp-for=&quot;@Model.employeePermissions.RoleClaims[i].Type&quot; type=&quot;hidden&quot; /&gt;
                          @Model.basePermissions.RoleClaims[i].Type
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input asp-for=&quot;@Model.employeePermissions.RoleClaims[i].Value&quot; type=&quot;hidden&quot; /&gt;
                          @Model.basePermissions.RoleClaims[i].Value
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;div class=&quot;form-check m-1&quot;&gt;
                              &lt;input asp-for=&quot;@Model.employeePermissions.RoleClaims[i].Selected&quot; class=&quot;form-check-input&quot; /&gt;
                          &lt;/div&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              }
          &lt;/tbody&gt;
      &lt;/table&gt;
  
      &lt;h4&gt;Users&lt;/h4&gt;
      &lt;table class=&quot;table table-striped&quot; id=&quot;permissionTable&quot;&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      Type
                  &lt;/th&gt;
                  &lt;th&gt;
                      Permission
                  &lt;/th&gt;
                  &lt;th&gt;
                      Status
                  &lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
  
              @for (int i = 0; i &lt; Model.userPermissions.RoleClaims.Count(); i++)
              {
                  &lt;tr&gt;
                      &lt;td&gt;
                          &lt;input asp-for=&quot;@Model.userPermissions.RoleClaims[i].Type&quot; type=&quot;hidden&quot; /&gt;
                          @Model.basePermissions.RoleClaims[i].Type
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;input asp-for=&quot;@Model.userPermissions.RoleClaims[i].Value&quot; type=&quot;hidden&quot; /&gt;
                          @Model.basePermissions.RoleClaims[i].Value
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;div class=&quot;form-check m-1&quot;&gt;
                              &lt;input asp-for=&quot;@Model.userPermissions.RoleClaims[i].Selected&quot; class=&quot;form-check-input&quot; /&gt;
                          &lt;/div&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              }
          &lt;/tbody&gt;
      &lt;/table&gt;
  
  
  &lt;/div&gt;
  @section Scripts {
      @{await Html.RenderPartialAsync(&quot;_ValidationScriptsPartial&quot;);}
  }
  </code></pre>
  <pre><code>using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Identity;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.AspNetCore.Mvc.RazorPages;
  using MosaicTitlePro.Helpers;
  using MosaicTitlePro.Models.ViewModels;
  using MosaicTitlePro.Permission;
  
  namespace MosaicTitlePro.Pages.User
  {
      public class RolesPermissionsModel : PageModel
      {
          private readonly RoleManager&lt;IdentityRole&gt; _roleManager;
  
          public RolesPermissionsModel(RoleManager&lt;IdentityRole&gt; roleManager)
          {
              _roleManager = roleManager;
          }
          public PermissionViewModel basePermissions { get; set; }
          public PermissionViewModel employeePermissions { get; set; }
          public PermissionViewModel userPermissions { get; set; }
  
          public async Task OnGetAsync(string Id)
          {
              string roleId = Id;
              basePermissions = await GetRolePermissionsAsync&lt;Permissions.Base&gt;(roleId);
              employeePermissions = await  GetRolePermissionsAsync&lt;Permissions.Employee&gt;(roleId);
              userPermissions =  await GetRolePermissionsAsync&lt;Permissions.Base&gt;(roleId);
          }
  
          public async Task&lt;RedirectToActionResult&gt; OnPostBaseAsync(PermissionViewModel model)
          {
              await PutRolePermissionsAsync(model);
  
              return RedirectToAction(&quot;Index&quot;, new { roleId = model.RoleId });
          }
  
          protected async Task&lt;PermissionViewModel&gt; GetRolePermissionsAsync&lt;T&gt;(string roleId)
          {
              var model = new PermissionViewModel();
              var allPermissions = new List&lt;RoleClaimsViewModel&gt;();
              allPermissions.GetPermissions(typeof(T), roleId);
              var role = await _roleManager.FindByIdAsync(roleId);
              model.RoleId = roleId;
              model.RoleName = role.Name;
              var claims = await _roleManager.GetClaimsAsync(role);
              var allClaimValues = allPermissions.Select(a =&gt; a.Value).ToList();
              var roleClaimValues = claims.Select(a =&gt; a.Value).ToList();
              var authorizedClaims = allClaimValues.Intersect(roleClaimValues).ToList();
              foreach (var permission in allPermissions)
              {
                  if (authorizedClaims.Any(a =&gt; a == permission.Value))
                  {
                      permission.Selected = true;
                  }
              }
              model.RoleClaims = allPermissions;
              return model;
          }
  
          protected async Task PutRolePermissionsAsync(PermissionViewModel model)
          {
              var role = await _roleManager.FindByIdAsync(model.RoleId);
              var claims = await _roleManager.GetClaimsAsync(role);
              foreach (var claim in claims)
              {
                  await _roleManager.RemoveClaimAsync(role, claim);
              }
              var selectedClaims = model.RoleClaims.Where(a =&gt; a.Selected).ToList();
              foreach (var claim in selectedClaims)
              {
                  await _roleManager.AddPermissionClaim(role, claim.Value);
              }
             
          }
      }
  }
  </code></pre>
  <pre><code>    public class PermissionViewModel
      {
          public string RoleId { get; set; }
          public string RoleName { get; set; }
          public IList&lt;RoleClaimsViewModel&gt; RoleClaims { get; set; }
      }
  
      public class RoleClaimsViewModel
      {
          public string Type { get; set; }
          public string Value { get; set; }
          public bool Selected { get; set; }
      }
  </code></pre>