I'm working on an AdminPortal and I have a database setup as such:
User 1:N UserRole N:1 Role 1:N RolePage N:1 Page
So, a user is connected to a role via the UserRole table, and the role to a specific page via the RolePage table.
I used MVC5 and the Entity Framework to make my Models and Controllers.
In my UsersController I want the Details to show the Roles as well, which it currently does not. From here someone should be able to pick Edit and then add/remove Roles for the specific User.
When I try to use the existing user.UserRoles, as such:
@Html.DisplayNameFor(model => model.UserRoles)
I get an output of:
System.Data.Entity.DynamicProxies.Role_2928XXXXXXXXXXXXX
And I want to see a list of the Roles assigned to them (i.e., Admin, Sales, etc.) What is the best way to do this??
Here is the Details part of my Controller:
// GET: Users/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
User user = db.Users.Find(id);
if (user == null)
{
return HttpNotFound();
}
return View(user);
}