Firstly, if you're researching this you'll want to get the right name -
this isn't a list, it's a tree.
Now, as for implementing it, assuming you want the same content type at
all locations, you could do something along the lines of:
public class TreeNode<T>
{
T content;
TreeNode<T> parent; // Will be null for the root
IList<TreeNode<T>> children;
}
What API you put on top of that is up to you, of course.
--
Jon Skeet - <
[email protected]>
Web site:
http://www.pobox.com/~skeet
Blog:
http://www.msmvps.com/jon.skeet
C# in Depth:
http://csharpindepth.com
Basically, I need to render in my MVC project the following:
<ul id="Menu" class="Menu-Smog">
<li><%= Html.ActionLink("home", "Index", "Home") %></li>
<li>
<a href="#CMS">Cms</a>
<ul>
<li><%= Html.ActionLink("Create Post", "Create", "Post") %></li>
<li><%= Html.ActionLink("Delete File", "Delete", "File") %></li>
</ul>
</li>
<li><%= Html.ActionLink("Contact", "Contact", "Home") %></li>
</ul>
So basically I each Tree Node should render as follows:
1. Is Not Active
<li><a href="#CMS">Cms</a></li>
2. Is Not Active but has child items
<li>
<a href="#CMS">Cms</a>
<ul>
### Child Items Go Here ###
</ul>
</li>
3. Is Active and does not have child elements
<li><%= Html.ActionLink( { Link Name }, { Action },
{ Controller } ) %></li>
4. Is Active and has child elements:
<li>
<li><%= Html.ActionLink( { Link Name }, { Action },
{ Controller } ) %></li>
<ul>
### Child Items Go Here ###
</ul>
</li>
So each Tree Node should have the following properties: ID, IsActive,
Name, Action and Controller
And the ability to check if it contains child items and if there is
loop through their child items applying the same rules ...
My problem is more with how the object should be and how to loop
through the Tree and follow this rules ...
Thanks,
Miguel