MenuPinned and selected state

Apr 5, 2010 at 11:15 AM

Great solution!

I am using Html.MenuPinned() to generate a sub menu, all good. However, I was expecting the submenu to allow for passing a selected state css class (as per Html.Menu()) so that I could have my main menu highlight AND have the submenu highlight. Is this possible without any extra coding?

Cheers,
Andles

Apr 6, 2010 at 6:47 AM
Edited Apr 6, 2010 at 9:25 AM

No response as of yet, so made some edits to the source code as per below. The version of Menu() call by MenuPinned() passes String.Empty for the cssSelectedClass - so all I have done is allowed the 'if' statement to allow through the empty string, and hard coded the name of my css class "selected". Short term solution and will await reply to my original post...seems odd to me that this isn't already a feature so possible I am reinventing the wheel here...

 

                   if (selectedSiteMapProvider.CurrentNode != null &&
                            (selectedSiteMapProvider.CurrentNode.Equals(node)
                                || (selectedSiteMapProvider.CurrentNode.IsDescendantOf(node) && !node.Equals(selectedSiteMapProvider.RootNode))
                            )
                       )
                    {

                        sb.Append("<li");
                       

                        // if (!string.IsNullOrEmpty(selectedMenuItemCssClass))
                        // REPLACED THE CODE ABOVE WITH WITH THE CODE BELOW
                        if ( selectedMenuItemCssClass != null)
                        {                           

                            // sb.Append(string.Format(" class=\"{0}\"", selectedMenuItemCssClass));
                           // REPLACED THE CODE ABOVE WITH WITH THE CODE BELOW
                            sb.Append(string.Format(" class=\"{0}\"", "selected"));
                           // Todo: pass in css class name instead of hard coding.


                        }
                        sb.Append(">");
                    }
                    else
                    {
                        sb.Append("<li>");
                    }

Apr 6, 2010 at 9:03 AM

Fyi: was worried about side effects, but seems fine to, within MenuPinned() method, to add a new parameter for the selectedMenuItemCssClass - and then pass that to the call to Menu().

(as opposed to hard coding the css class name)

Coordinator
Apr 6, 2010 at 9:45 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.