I have the following code that creates a submenu based on current document. The document has children, which I use to build a submenu.
How do I check when I am on a current item? I want to style a an item on the submenu when that item is the current one.
I know I can do if (Model.Id == page.Id) to find the current item but this does not work
with Documents.
This is the code I want to modify.
@foreach (var node in new Document(999).Children)
{
<li>@node.Id</a>
@{ var mychildren = node.Children;
if (mychildren.Count() > 0)
{
<ul>
<li>@node.id</a></li>
@foreach (var snode in mychildren)
{
<li>@snode.id</a></li>
}
</ul>
}
</li>
}
}
Why don’t you use DynamicNode instead of Document, then use a helper to check for and add the class? Example:
(The Library.NodeById method returns a DynamicNode object.)