Greetings all. In my MVC app I am trying to iterate through 2 collections, which are similar to a jagged array (a collection of modules, each containing a collection of components). Module and Component each have an Index attribute where the sort order is specified through an admin tool. The flow:
1) Get the user's assigned presentation (pid)
2) Get the modules contained in the pid (mndx), indexed ascending - set index variable
3) Get the components in each mndx, indexed ascending - set index variable
4) Get module index 1 - iterate from component index 1 to last index
5) Iterate to module index 2 - iterate from component index 1 to last index
6) Pass iteration of mIndex and iteration of cIndex in TempData to PartialView Controller action for rendering.
7) ...Rinse and repeat through modules and components until done
My code is below - can anyone see a way to do this? (I know I can't convert Components ToList, but I am stuck).
var Modules = db.PresentationModules
.Where(m => m.PresentationId == pid)
.OrderBy(m => m.ModuleIndex)
.Select(m => m.ModuleIndex)
.ToList();
List<ModuleComponent> Components = new List<ModuleComponent>();
foreach (int mndx in Modules)
{
Components = db.ModuleComponents
.OrderBy(m => m.ComponentIndex)
.Select(m => m.ComponentIndex)
.ToList();
}
for (int i = 0; i < Modules.Count; i++)
{
mIndex = i;
for (int c = 0; c < Components.Count; c++)
{
cIndex = c;
}
}