Hi I have an application in which i have User , Roles and USer&Roles Tables My User table is just like below
USER (UserId,NAme)
Roles(RoleId,RoleName)
User&Roles(tableid,UserId,RoleId)
Although I have other columns as well but for simplicity i am taking only the required ones .
I have records in my User table , Roles table and User&roles table Like below
User Table(1,SAN)(2,JAH)(3,HOP)
Role TABLE(1,Admin)(2,Customer)(3,Super-ADmin)
User&Roles(1,1,1)(2,1,2)(3,2,2)(4,2,3)
As you can see My user id =1 is having two roles and user id 2 is having one role
I want to show the records on index view such like that as user id =1 is having two roles in the database table (user&Roles) i want to show one row but on role_name column i want comma seperated list of roles assigned to him rather than showing all rows with new role_name and all other information same .
What I have tried:
I have showed but it shows all rows like the link
<pre>@model IEnumerable<CMS_Monitoring.Models.UserRoles>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout2.cshtml";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.User_Id)
</th>
<th>
@Html.DisplayNameFor(model => model.Active)
</th>
<th>
@Html.DisplayNameFor(model => model.Role_Id)
</th>
<th>
@Html.DisplayNameFor(model => model.Date_Assigned)
</th>
<th>
@Html.DisplayNameFor(model => model.Date_Created)
</th>
<th>
@Html.DisplayNameFor(model => model.Date_Modified)
</th>
<th>Actions</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Registration.Username)
</td>
<td>
@Html.DisplayFor(modelItem => item.Active)
</td>
<td>
@Html.DisplayFor(modelItem => item.Roles.Role_Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date_Assigned)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date_Created)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date_Modified)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
</tr>
}
</table>