1

I'm a tad rusty here so bear with me. I'm trying to get my list of items within their groups like so.

  <h2>Category Heading 1</h2>
   <ul>
     <li>Item list 1</li>
    <li>Item list 2</li>
   </ul>


  <h2>Category Heading 2</h2>
   <ul>
     <li>Item list 1</li>
    <li>Item list 2</li>
   </ul>

And my code is - I'm getting errors

 @foreach (var group in db.Query(GroupName)){
    <h3>@group.Name</h3>
<ul>
    @foreach(var row in db.Query(queryList)){
  <li><a href="/DataVideo?id=@row.ID"> @row.title</a></li> 
  }
 </ul>
}

Any help would be appreciated

NickP
  • 357
  • 1
  • 7
  • 18

1 Answers1

1

You should be able to do this by getting all the data in one go and using the LINQ GroupBy operator. Here is an article I wrote about displaying hierarchical data like this: http://www.mikesdotnetting.com/Article/189/Efficiently-Displaying-Hierarchical-Data-With-The-jQuery-Accordion-In-Razor-Web-Pages

You can ignore the 2nd half where I introduce the jQuery accordion...

Mike Brind
  • 28,238
  • 6
  • 56
  • 88
  • Mike That is exactly it and what I was after. Thank you for your help. Regards NickP – NickP Feb 20 '13 at 06:51
  • Works like a charm too, without executing multiple database queries to obtain data as stated in your article :-) – NickP Feb 20 '13 at 09:18