Skip to content
Loading
Making a single row with comma separated list in mvc
0
  • Ashutosh Gupta hi can you update my view and controller i am not getting how to achieve it using this approach the first one you are talking about .....

    0
  • Ashutosh Gupta
    Mark, there are two options 1. You can directly send groupedUsers to view and loop inside view using razor page.. 2. You can create new view model and assign list of name and hobby into it and send that view model to view.
    0
  • Ashutosh Gupta although I am making the group in controller code but not able how to use it in view check below code of my group 

    Teacher_courses[] productsArray = dept.ToArray();
    var groupedUsers = from u in productsArray
    group u by u.regs.FirstName into g
    select new
    {
    Name = g.First().Teacher_Id,
    Hobby = g.Select(u => u.Course_Id)
    };
    foreach (var user in groupedUsers)
    {
    Console.WriteLine("Teacher_ID: {0}", user.Name);
    foreach (var hobby in user.Hobby)
    {
    Console.WriteLine("Course_ID: {0}", hobby);
    }
    }
    hobby -->courses
    user-->Teacher Name 
    0
  • I need vice versa as well so it is many to many and there is a need to have a separate table .
    0
  • Ashutosh Gupta
    Mark, 
    why dont you introduce coloumn in teach table with List of courses
    List courses as part of teach table, you do not need seprate table to maintain such references. 
    i hope you don't need vice versa, getting all teachers from coures ?  
    0