I create a page with a table that displays all users. I need in the column next to display the user roles. I try to do it as follows:

<td> @Html.DisplayFor(modelItem => Model.Roles.First(p => p.Value == item.Roles.ToArray()[0].RoleId)) </td> 

Gives an error message:

Patterns can only be used with field referrals, property accesses, a one-dimensional array index, and a custom indexer with a single parameter.

    2 answers 2

    Or so

     <td> @Html.DisplayFor(modelItem => modelItem.Roles.First(p => p.Value == item.Roles.ToArray()[0].RoleId)) </td> 

    or so

     <td> @Html.DisplayFor(@Model.Roles.First(p => p.Value == item.Roles.ToArray()[0].RoleId)) </td> 

      To print not only the roles, hung through a standard provider, such as Active Directory, but also your own, it is better to use claims

       if (User.Identity.IsAuthenticated) { var identity = User.Identity as ClaimsIdentity; if (identity != null) { foreach (var claim in identity.Claims) { <p>@claim</p> } } }