5

can anybody point me in the right direction as to how I would go about implementing a hierarchical navigation menu which is driven by database? I don't want to re-invent the wheel here, so I was wondering if there is something that's already been done. I'm aware of the Menu control in asp.net, but from what I figure it won't work with MVC. Is there something that's already provided as part of the framework that I can leverage for this purpose? If not, then maybe a few links to point me in the right direction?

thanks.

Alconja
  • 14,834
  • 3
  • 60
  • 61
Riz
  • 6,486
  • 19
  • 66
  • 106

2 Answers2

3

LBushkin's idea is a good one. For ways to emit the <ul> and <li> tags from the database, have a look at the following blog posts:

ASP.NET MVC Recursive TreeView Helper
http://www.matthidinger.com/archive/2009/02/08/asp.net-mvc-recursive-treeview-helper.aspx

Rendering a TreeView using the ASP.NET MVC Framework http://mikehadlow.blogspot.com/2008/10/rendering-tree-view-using-mvc-framework.html

I personally use a modified version of Matt Hidinger's recursive TreeView Helper, and feed it a couple of IQueryables from my database.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
  • Is there any code for reading the data from database and populating the tree with LINQ to SQL or LINQ to ADO.Net entity? – Tanmoy Aug 25 '10 at 14:00
  • @Tanmoy: See here...http://stackoverflow.com/questions/202912/hierarchical-data-in-linq-options-and-performance – Robert Harvey Aug 25 '10 at 20:06
2

You may want to look at superfish - it's a jQuery compatible menu control that's flexible and uses semantic markup. You can menus by just emitting an appropriate set of <ul> and <li> tags. They can even be nested to create hierarchical menus by just nesting lists within other lists.

It doesn't directly interface with a database representation - but it's easy enough to emit such a structure into markup as <ul> tags and apply superfish to it.

LBushkin
  • 129,300
  • 32
  • 216
  • 265