title: How to get name of roles in Views from IdentityUser in asp.net mvc?
body: <p>I am trying to display a list of Roles in my index view but there seems to be no possible way to access dbo.AspNetRoles??</p>
  
  <p>ROLE MAINTENANCE CONTROLLER:</p>
  
  <pre><code>namespace DwBusService.Controllers
  {
      public class DwRoleMaintenanceController : Controller
      {
          // private readonly ApplicationDbContext _context;
          private readonly RoleManager&lt;IdentityRole&gt; roleManager;
          private readonly UserManager&lt;ApplicationUser&gt; userManager;
  
          public DwRoleMaintenanceController(RoleManager&lt;IdentityRole&gt; roleManager, UserManager&lt;ApplicationUser&gt; userManager)
          {
              this.roleManager = roleManager;
              this.userManager = userManager;
          }
  
          // GET: DwRoleMaintenance
          public async Task&lt;IActionResult&gt; Index()
          {
              var roles = roleManager.Roles.OrderBy(a =&gt; a.Name);
              return View(roles);
          }
      }
  }
  </code></pre>
  
  <p>APPLICATION USER MODEL</p>
  
  <pre><code>namespace DwBusService.Models
  {
      // Add profile data for application users by adding properties to the ApplicationUser class
      public class ApplicationUser : IdentityUser
      {
          public ApplicationUser()
          {
          }
          [Display(Name = "Local Authentication")]
          public bool LocalAuthentication { get; set; }
      }
  }
  </code></pre>
  
  <p>INDEX ROLE MAINTENANCE VIEW</p>
  
  <pre><code>@model IEnumerable&lt;DwBusService.Models.ApplicationUser&gt;
  ....
  &lt;table class="table"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;@Html.DisplayNameFor(model =&gt; model.Roles)&lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
      @foreach (var item in Model) {
          &lt;tr&gt;
              &lt;td&gt;@Html.DisplayFor(modelItem =&gt; item.Roles)&lt;/td&gt;
              &lt;td&gt;
                  &lt;a asp-action="Edit" asp-route-id="@item.Id"&gt;Edit&lt;/a&gt; |
                  &lt;a asp-action="Details" asp-route-id="@item.Id"&gt;Details&lt;/a&gt; 
                  &lt;a asp-action="Delete" asp-route-id="@item.Id"&gt;Delete&lt;/a&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      }
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I cannot access <code>Roles.Name</code> or <code>Roles.Id</code> from <code>item.Roles</code>. I have tried to create a <code>virtual RoleNavigation</code> property in Application user, I have tried to make my own <code>IdentityRole.cs</code> model, I have tried many things. Can anyone help me? When I run this code as is I get this error:</p>
  
  <blockquote>
    <p>InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable'1[Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityRole]', but this ViewDataDictionary instance requires a model item of type 'System.Collections.Generic.IEnumerable'1[DwBusService.Models.ApplicationUser]'.</p>
  </blockquote>
  
  <p>DBO.ASPNETROLES.SQL</p>
  
  <pre><code>CREATE TABLE [dbo].[AspNetRoles] (
      [Id]               NVARCHAR (450) NOT NULL,
      [ConcurrencyStamp] NVARCHAR (MAX) NULL,
      [NormalizedName]   NVARCHAR (256) NULL,
      CONSTRAINT [PK_AspNetRoles] PRIMARY KEY CLUSTERED ([Id] ASC)
  );
  
  
  GO
  CREATE NONCLUSTERED INDEX [RoleNameIndex]
      ON [dbo].[AspNetRoles]([NormalizedName] ASC);
  </code></pre>