I would like to dispaly the Name Ben only as Admin and the Name User1 as User but it gives me both of them in table see picture & the code what I have tried please :
Python
@model ePizzaHub.WebUI.ViewlModel.AdminRoleView
@{
ViewData["Title"] = "Index";
}
Admin Dashboard
Name
Email
Admin
@foreach (var item in Model.Users)
{
@item.Name
@item.Email
@foreach (var role in Model.Roles)
{
@role.Name
}
}

Hardik DhankechaRank #9,518 · 205 reputationPosted Sep 11, 2021, 9:32 AM EDT
Hi Abdalla,
You need to manage role name properly in your database. Like assigning the Admin role to Ben and the User role to User1. Now only you need to attach the role name with your AdminRoleView.Users data. It will display proper role with users in the gird section.
Also, there are multiple ways to handle a role properly. As you can manage roles with another role table in db. And assign a role id to the user. Also, you can manage parent and child role concept using it.
For example :
RoleTable :
UserTable :
There are multiple ways to perform roles, roles& rights. Above is a basic and simplest way to perform roles with users. By using the above technique, you will be able to display role in a nested view under your gird. Like all users, list under admin.
Happy Coding...!!!
Sachin SinghRank #66 · 26.2K reputationPosted Sep 10, 2021, 11:17 AM EDT
Rijwan AnsariRank #82 · 24.2K reputationPosted Sep 10, 2021, 12:45 PM EDT