Sumon Sumon

Sumon Sumon

  • NA
  • 77
  • 4.3k

Nested foreach in C# MVC?

Sep 21 2018 3:08 AM
I'm New to C# MVC and I'm failed to implement following situation, I have a database and it's table Data like below
 
 Company Branch Section Employee_ID
 abc ltd. branch11 section1 111001
 abc ltd. branch11 section2 221001
 xyz ltd. branch11 section1 551001
 xyz ltd. branch22 section1 551001
Each Company has separate Branch, Each Branch has Separate Section Each Section has Separate Employee_ID
 
I need a Model Class and A Razor View to represent the Data with a nested foreach loop like below.
 
foreach(var company in model.Company)
{ foreach ( var branch in company)
{ foreach (var section in branch)
{ foreach ( var empid in section)
}
}
}
 
Is it possible? How I write the model class? Data needs to be looked like
abc ltd.
    branch11
    section1
  111001
  section2
  221001
xyz ltd.
    branch11
    section1
    551001
    branch22
    section1
    661001

Answers (1)