<p>I am trying to come up with the best way to render some hierarchical data in to a nested unordered list using ASP.NET MVC. Does anyone have any tips on how to do this?</p>

[{'answer_id': 58170, 'author': 'Ben Scheirman', 'author_id': 3381, 'author_profile': 'https://Stackoverflow.com/users/3381', 'pm_score': 1, 'selected': False, 'text': "<p>You mean... you want some sort of tree view?</p>\n\n<p>You can actually get the treeview control to work... but you have to wrap it in server side form tag to function.  You'll get the usual nastiness that that brings (like generated ids and viewstate) but it will work from a rendering perspective.</p>\n\n<p>If you want to just create  tags and nest them, it would be pretty easy to do with foreach() loops.</p>\n"}, {'answer_id': 58345, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 2, 'selected': True, 'text': '<p>I suggest jquery tree view plugins for making it function like a tree, but as for render, just put it in a recursive lambda helper to do the nesting.</p>\n'}, {'answer_id': 66711, 'author': 'Hrvoje Hudo', 'author_id': 1407, 'author_profile': 'https://Stackoverflow.com/users/1407', 'pm_score': 0, 'selected': False, 'text': "<p>For that (rendering hierarchical menu, treeview, etc) i use recursive calls of custom component (ascx, or aspx in new preview5).<br>\nI give component first level of items (List of items), and component then check for each item in list if there's any child items and call itself with list of that child items.<br>\nYou can build hierarchical graph of objects in controller, or just 1 dimensional list with ParentID property.</p>\n"}, {'answer_id': 280736, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>I believe currently there is no such control.... TreeViews are complex by nature. You can of course "draw" a hierarchy as much as you like using all sorts of <em>repeaters</em> and loops, but to achieve <strong>functionality</strong> of a tree view like the one in the Web forms toolbox... you have to wait !</p>\n'}, {'answer_id': 282066, 'author': 'Paco', 'author_id': 13376, 'author_profile': 'https://Stackoverflow.com/users/13376', 'pm_score': 1, 'selected': False, 'text': "<p>Why don't you pass your model in the form of a tree to the view?</p>\n\n<pre><code>/// This is the model class\npublic class MyTreeNode&lt;T&gt;\n{\n    public ICollection&lt;MyTreeNode&gt; ChildNodes {get;}\n    public T MyValue { get; set; }\n    bool HasChildren { get { return ChildNodes.Any(); } }\n}\n\n///This is the html helper:\npublic static string RenderTree&lt;T&gt;(this HtmlHelper html, MyTreeNode&lt;T&gt; root, Func&lt;T, string&gt; renderNode)\n{\n    var sb = new StringBuilder();\n    sb.Append(renderNode(root.MyValue));\n    if (root.HasChildren)\n    {\n        foreach(var child in root.ChildNodes)\n        {\n            sb.Append(RenderTree&lt;T&gt;(html, child, renderNode));\n        }\n    }\n    return sb.ToString();\n}\n</code></pre>\n\n<p>I didn't actually test this code, but it's about the idea. You can imagine creating your own recursive html helper to render a tree.</p>\n"}]
['https://Stackoverflow.com/questions/58146', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5360/']