title: How do I get an AppUser's role in Razor?
body: <p>For my Users List View I send down a list of AppUser : IdentityUser like this:</p>
  
  <pre><code>    public AccountAdminController(UserManager&lt;AppUser&gt; userManager,
          RoleManager&lt;IdentityRole&gt; rolesManager)
      {
          _userManager = userManager;
          _roleManager = rolesManager;
      }
  
      // List Users
      public ViewResult Index()
      {
          return View(_userManager.Users);
      } 
  </code></pre>
  
  <p>I render the users in the View like this:</p>
  
  <pre><code>@model IEnumerable&lt;AppUser&gt;
  
  foreach (AppUser user in Model)
  {
      &lt;tr&gt;
          &lt;td&gt;@user.Id&lt;/td&gt;
          &lt;td&gt;@user.UserName&lt;/td&gt;
          &lt;td&gt;Role&lt;/td&gt;
          &lt;td&gt;@user.Email&lt;/td&gt;
          &lt;td&gt;
              &lt;a id="editModal" data-toggle="modal" data-target="#modal_box"
                                 class="btn btn-sm btn-primary"
                                 asp-action="EditUser" asp-route-id="@user.Id"&gt;Edit&lt;/a&gt;
              &lt;a id="deleteConfirmModal" data-toggle="modal" data-target="#modal_box"
                                 class="btn btn-sm btn-danger"
                                 asp-action="DeleteConfirm" asp-route-id="@user.Id"&gt;Delete&lt;/a&gt;
         &lt;/td&gt;
     &lt;/tr&gt;
  }
  </code></pre>
  
  <p>How can I get the role of each user in the role column?</p>
  
  <p>The roles collection for each user is empty, count 0, even when I know the user has a role.  Each user will only have one role so I need to pull @user.Roles.FirstOrDefault().Name.</p>
  
  <p>But it's not there.
  How can I get around this?</p>
  
  <h2>UPDATE 1</h2>
  
  <p>if I do this with an include:</p>
  
  <pre><code>    public ViewResult Index()
      {
          return View(_userManager.Users.Include(u =&gt; u.Roles));
      } 
  </code></pre>
  
  <p>And then in the view:</p>
  
  <pre><code>&lt;td&gt;@user.Roles&lt;/td&gt;
  </code></pre>
  
  <p>It renders this:</p>
  
  <pre><code>System.Collections.Generic.List`1[Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityUserRole`1[System.String]]
  </code></pre>
  
  <p>Now if I try to extend the razor line:</p>
  
  <pre><code>@user.Roles.FirstOrDefault().
  </code></pre>
  
  <p>The only thing I get in intellisense is RoleId, no Name for Role.</p>