-4

I have a unique sql database setup in which I'm using nested sets to determine the hierarchy. Here's an example of it:

HierarchyID = 1, HierarchyText = "Contract", HierarchyLeft = 1, HierarchyRight = 54

HierarchyID = 2, HierarhcyText = "Part 1...", HierarchyLeft = 2, HierarchyRight = 41

HierarchyID = 3, HierarchyText = "Part 2...", HierarchyLeft = 42, HierarchyRight = 45

HierarchyID = 8, HierarchyText = "General Provisions", HierarchyLeft = 3, HierarchyRight = 40

The idea is that the children (or subcategories) are contained within the parent's LEFT and RIGHT values. So, for instance, "General Provisions" is a child of "Part 1..." which is a child of "Contract". "Part 1..." and "Part 2" are siblings of each other since they don't contain each other going by the left and right values.

The question I have is this: Is there a way to use MVC3 with Razor Engine to create a tree and display it pulling from this database? The only examples I've seen have been databases that have each node in the database pointing to its parent. If it's possible, could you provide sample code for the CONTROLLER and VIEW? I'd appreciate that. Also, I'm able to pull the hierarchy names by level. So, I'd appreciate an example in which I could feed the tree control a level at a time. For instance, feed the top level... when the user clicks on it, feed the next leve, etc. down the tree. I would really appreciate any help!

TheDude
  • 1,421
  • 4
  • 29
  • 54

1 Answers1

1

You seem to be using the Nested Set Model to define hierarchical data. Personally I would use recursive display templates once the data is fetched from the database into a view model to display the tree. Here's an example in which I illustrated similar concepts in action which you could adapt to meet your specific requirements.

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I see that my question isn't very popular around here, but I really do appreciate your help. It really did help. Thanks again! – TheDude May 23 '12 at 17:38
  • @TheDude, if you found this answer helpful you might consider marking it as answer by clicking on the tick next to it: http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Darin Dimitrov May 23 '12 at 20:04
  • Thanks, Darin. One more question: Would it be possible to populate a tree level-by-lever rather than the entire tree at once? In other words, I'd like to populate the top level.. the user clicks on it, then it pulls in the second level, and so on. – TheDude May 24 '12 at 01:40