Hi I am trying to create a dynamic menu an I seem to have gotten into some trouble.
The problem is that when run the application only the items belonging to the last category get displayed repeatedly for all categories.
There are two places where I might have made the mistake but I can not be sure wicth is the place I made it I will also post a diagram of the two tables I am working with.This is the diagram:

I am using LINQ TO SQL to acces the database and have created a separate class to do this.Here is the code for accesing the data.This is the first place where I might have made the mistake when adding the items to the Dictionary aldo I stepped over this method with the debugger and it seems to be ok I can not be sure so I posted it:
public Dictionary<string , List<string>> subCatByCatList() {
Dictionary<string , List<string>> SubcatByCat = new Dictionary<string , List<string>>();
var subcategoriesByCategory = from category in dataContext.Categories
join subcategory in dataContext.SubCategories
on category.CatId equals subcategory.CatId
into cs
select new {
CategoryName = category.CatName ,
SubCategories = cs
};
List<string> subcategories = new List<string>();
foreach( var category in subcategoriesByCategory ) {
string CategoryName = category.CategoryName;
subcategories.Clear();
foreach( var subCategory in category.SubCategories ) {
subcategories.Add(subCategory.SubCatName);
}
SubcatByCat.Add(CategoryName , subcategories);
}
return SubcatByCat;
}
THe seccond place is when I am trying to display the data.This is where I most likely think I made the mistake when I tryed to display it.Here is the code:
@{
ComputerStoreDataAccess data = new ComputerStoreDataAccess();
Dictionary<string, List<string>> nav = data.subCatByCatList();
<ul>
@foreach (var category in nav)
{
<li><a href="#">@category.Key</a></li>
foreach (var subcategory in category.Value)
{
<div>
<ul>
<li>@subcategory</li>
</ul>
</div>
}
}
</ul>
}
EDIT

In this loop you have to create the
subcategoriesobject on every iteration, otherwise you have reference to single list in aSubcatByCat: