Programatically select highlighted navigation

Topics: Customizing Orchard
Oct 22, 2012 at 12:05 PM
Edited Oct 22, 2012 at 2:23 PM

As subject, is it possible to programatically select which navigation items are highlighted from a custom controller?

Thanks in advance for any replies.



I found a way to hack this to work after a little debugging, but it's very dirty. 

I placed 


var routeData = Request.RequestContext.RouteData;
            routeData.Values["area"] = "Contents";
            routeData.Values["controller"] = "Item";
            routeData.Values["action"] = "Display";
            routeData.Values["Id"] = "105";

inside my controller, where the route values match the required navigation node, but this meant adding a corresponding view at Item/Display.cshtml inside my area. 

There has to be a better way. Any ideas?



Oct 31, 2012 at 11:31 PM

MenuItems have a Selected property which you can set when Orchard builds the menu structure. I think there's an IMenuFilter that you can implement to process the menu items (see the source code in the core Navigation module and in the Navigation folder of Orchard. Framework to find out which providers are being invoked).