2

I have an asp.net backend that creates Hierarchical Data based on IHierarchicalEnumerable.

This was used for custom Hierarchical Data Controls in ASP.NET WebForms for sitemaps etc. We are now using ASP.NET MVC and am looking to use the same Hierarchical Data Collection with jQuery / Json etc.

How can I display Hierarchical Data using IHierarchicalEnumerable?

Is it possible (or a good idea) to return the IHierarchicalEnumerable as a JsonResult and iterate through this jQuery or should we just iterate through this within the view? Any Ideas on which one is better and how to do this?

Added:

Ideally we want to render say a treeview via Json/Ajax, so that would need to be a jQuery recursive approach if the object (IHierarchicalEnumerable ) is supported, not sure how efficient this would be though. Thinking an alternative approach to IHierarchicalEnumerable might be worth investigating...

Mark Redman
  • 24,079
  • 20
  • 92
  • 147
  • Why is this question different from the related ones in the right column? This has been answered a bunch of times and with your reputation I'd assume you already checked them. – John Farrell Oct 11 '10 at 22:43
  • Not sure which one you're reffering to, but a search for: jquery IHierarchicalEnumerable now only reveals this question. I can only find references to binding to UserControls or WebControls in an ASP.NET WebForms environment, nor rendering on page with jQuery/Json or directly. – Mark Redman Oct 12 '10 at 07:56

1 Answers1

0

To keep things simple in this case (which in fact only requires a 2 level hierarchy) I have just used a basic Model that contains a list of sub-items...

Will asnwer it for now and may come back to it when I do a full nested hierarchy for treeview etc...

Mark Redman
  • 24,079
  • 20
  • 92
  • 147
  • I was wondering what type of solution you ended up using once you had a full hierarchy for the treeview. I am wondering how I would do this in MVC. In my 3.5 app I was outputting the results as a ul and sending it back in a ajax request and then using dynatree jquery plugin to tree it up. – Breadtruck May 28 '11 at 17:26
  • Hi, I just used basic Model (object with list and sublist properties) and loops within the view to keep things simple. I might try your idea for larger trees though... – Mark Redman May 29 '11 at 15:57
  • If you do end up doing something nice and simple that works well, please post it here as I have made your question a favorite. Thanks – Breadtruck May 29 '11 at 21:12
  • 1
    Also here is a thread that is related to this in a way, but maybe you will have a specific response. http://stackoverflow.com/questions/1129626/put-linq-to-sql-results-into-hierarchical-structure-for-using-in-a-un-ordered-lis – Breadtruck May 29 '11 at 21:15