I am working two database tables where UserDetaisl table holds details about Users having one or multiple Roles and Role table holds name of the Roles. I need to generate a HTML table something similar to the picture below. Where Each role from the Role table would be shown as a column and user with assigned role would be displayed as a check box ticked for that cell. non assigned role would show unticked check box. One user can have more than one role.
My classes look like:
public partial class UserDetails
{
public string username { get; set; }
public string role { get; set; }
public virtual Role Role1 { get; set; }
}
public partial class Role
{
public string Role1 { get; set; }
public virtual ICollection<UserDetails> UserDetails { get; set; }
}
Thought of creating a ViewModel which would show the Role selection.
public class RoleSelectionViewModel
{
public bool Selected { get; set; }
public bool NotSelected { get; set; }
public virtual Role Role1 { get; set; }
}
Not sure how to put all these toegther to generate the columns on the fly.
currentlty the following Controller method only lists all the users from the table with associated role.
public ActionResult Index()
{
var userDetails = db.UserDetails.Include(u => u.Role1);
return View(userDetails .ToList());
}
