I my ASP.NET MVC Core 3.1 app I have Model that stores professions which looks like this:
public partial class Professions
{
public int ProfessionID { get; set; }
public int? ProfessionGroupID { get; set; }
public string ProfessionTitle { get; set; }
public string ProfessionDescription { get; set; }
}
So each profession belongs to some group of professions, therefore Model for profession groups looks like this:
public partial class ProfessionGroups
{
public ProfessionGroups()
{
Professions = new HashSet<Professions>();
}
public int ProfessionGroupID { get; set; }
public int ProfessionGroupTitle { get; set; }
public string ProfessionGroupDescription { get; set; }
public virtual ICollection<Professions> Professions { get; set; }
}
How can I display list of groups of professions in one columns and list of professions in another column
with links which leads to each profession Details View?
This is how output table in some View should look:
| ProfessionGroups | Professions |
|---|---|
| Physiotherapy | Graduated physiotherapist Physiotherapist (bachelor degree) Physiotherapy technician |
| Geology | Geological technician Geology engineer |
So far I've created ViewModel that suppose to hold needed data:
public class ProfGroupsVM
{
public int ProfessionGroupID { get; set; }
public string ProfessionGroupTitle { get; set; }
public List<int> ProfIDs { get; set; } = new List<int>();
public List<string> ProfTitles { get; set; } = new List<string>();
}
For each ProfessionGroupID it has to populate ProfIDs with list of professions belonging to that group and ProfTitles should hold professions titles.
So in Controller so far I have:
var profGroupsVM= new ProfGroupsVM();
var result = from p in _context.Professions
group p.ProfessionID by p.ProfessionGroupID into g
select new { ProfessionGroupID = g.Key, ProfessionIDs= g.ToList() };
I don't know how to assign this result back to my ViewModel nor how to display desired View.