I am getting two lists in my function.
In first list I am getting list of all users for particular operation it’s code is as per below : Here in result I am getting full list of all users.
using (API = new APIHelper(APIURL, token))
{
result = APIManager.GetUserListperOperation(Id.Value);
}
Now I need to get role name for particular user based on User id, now one user can have multiple roles so in few cases I am getting multiple role records for one user.
Like user A has role A as well as role B etc..
For that below is code :
foreach(var userDetails in result)
{
role = APIManager.GetRoleperUser(userDetails.Id);
}
So I got two lists one is for users and other is for roles.
Now in view file I need to display list of users and also if user has more then one role then same user will display multiple times for each role,
Means user’s other details will be displayed same like first name, last name but role name will be displayed different for each row. Like below image.
I have tried below code :
@foreach (var item in result)
{
foreach(var userDetails in role)
{
<tr role="row" class="odd">
<td style="word-break:break-all">
@Html.DisplayFor(item.UserName)
</td>
<td>
@Html.DisplayFor(userDetails.RoleName)
</td>
</tr>
}
}
Any idea how to do this
2
Answers
I have make it working using following way.
I have created new class and created new dynamic list.
So Like Is said in my comment. You could either create the ‘list to loop’ before you create your table and then loop through it or create it in the controller and then loop through it (Which I think would be the easiest to do).
Then in the view just loop through the list: