asp.net mvc LINQ Finding out if any children or grandchildren exist with the current controller and Action
<p>I have a number of menu items with child menus and grandchild menues - two levels below the main menu item. I want to set the main menu item to active if one of the children or grandchildren have the same controller and index as the currentcontroller and current index.</p>

<p>This is my menuItem:</p>

<pre><code>public class MenuItem
{
    public int Id { get; set; }
    public bool Divider { get; set; }
    public bool Header { get; set; }
    public string ActionName { get; set; }
    public string ControllerName { get; set; }
    public string MenuItemText { get; set; }
    public IList&lt;string&gt; Roles { get; set; }
    public int ParentId { get; set; }

    public MenuItem()
    {

    }

    public MenuItem(int id, bool divider, bool header, string action, string controller, string menuItemText, IList&lt;string&gt; roles,int parentid)
    {
        Id = id;
        Divider = divider;
        Header = header;
        ActionName = action;
        ControllerName = controller;
        MenuItemText = menuItemText;
        Roles = roles;
        ParentId = parentid;
    }
}
</code></pre>

<p>Using viewcontext I have the currentcontroller and index.</p>

<pre><code>        var routeData = ViewContext.RouteData.Values;
        var currentController = routeData["controller"];
        var currentAction = routeData["action"];
</code></pre>

<p>Here is a subset of the menudata - the first is the main menu:</p>

<pre><code>        //Thats =&gt; Id, Divider, Header, ActionName, ControllerName, MenuItemText, List&lt;string&gt; roles, ParentId
        MenuList.MenuItems.Add(new MenuItem(800, false, true, null, null, "Admin", new List&lt;string&gt;() { "Admin" }, 0));

        MenuList.MenuItems.Add(new MenuItem(810, false, true, null, null, "User Admin", new List&lt;string&gt;() { "Admin" }, 800));
        MenuList.MenuItems.Add(new MenuItem(820, false, false, "Index/name_asc/false", "UserAdmin", "List Users", new List&lt;string&gt;() { "Admin" }, 810));
        MenuList.MenuItems.Add(new MenuItem(830, false, false, "Create", "UserAdmin", "New User", new List&lt;string&gt;() { "Admin" }, 810));
        MenuList.MenuItems.Add(new MenuItem(840, false, false, "FileIndexView", "SuburbsAndPostcodesAdmin", "Suburb &amp; Postcode Maintenance", new List&lt;string&gt;() { "Admin" }, 800));
</code></pre>

<p>You will note that the first one is the main menu and the parent id (last item) indicates the parent of that menu item. Parentid of "0" means its the top item.</p>

<p>This would not be an issue if the controller was the same all the way through but this particular menu item has a number of different controllers in it so I need a more sophisticated LINQ to first get all the menu items associated with the parent - children and grandchildren. Then test this list against the current controller and action.</p>

<p>How do I structure a LINQ query to get all the children and grandchildren of the menu item with a parent id == 0 (the top one in the example above)?</p>

<p>I can then run through the list once I have it but I am unsure how to get this list of all menuItems initially?</p>