Reputation: 333
I have a partial view within my main _Layout.cshtml. The partial view is used to display info about the logged in user.
The username can be displayed using @Context.User.Identity.Name
but I also want to display the role of the user.
What would be the best way to display this info?
Upvotes: 2
Views: 815
Reputation:
Loop through all of the user's roles in the View and display them accordingly:
@foreach(string role in Roles.GetRolesForUser(Context.User.Identity.Name))
{
@Html.Label(role);
}
This utilizes the Roles.GetRolesForUser()
method, and returns a string[]
for all the roles (each represented as a string
) the user is a part of.
Upvotes: 3