Set Current Menu Item to Selected

9 posts, 0 answers
  1. Chris
    Chris avatar
    27 posts
    Member since:
    May 2010

    Posted 30 Jul 2012 Link to this post

    I'm creating a Kendo.Mvc.UI.Menu in a Html Helper.  If the current controller/action matches the menu item then i set Selected to true. However, when the menu gets rendered to the page the current menu item is not selected.  Is there an init or onload event that is ignoring or overriding the Selected property?  It seems to only effect the current controller/action, if i set other menu items to Selected = true, they will stay selected.

    Kendo.Mvc.UI.Menu menu = Kendo.Mvc.UI.HtmlHelperExtension.Kendo(helper).Menu();
    menu.Name = "MainMenu";
      
    IList<MenuItem> items = new List<MenuItem>();
      
    items.Add(new MenuItem { Text = "Dashboard", Action = "Index", Controller = "Dashboard" });
    items.Add(new MenuItem { Text = "Certificates", Action = "Index", Controller = "Certificates" });
      
    UrlHelper Url = new UrlHelper(helper.ViewContext.RequestContext);
    string controller = helper.ViewContext.RouteData.GetRequiredString("controller");
      
    foreach (MenuItem item in items)
    {
          menu.Items.Add(new Kendo.Mvc.UI.MenuItem { Url = Url.Action(item.Action,item.Controller),Text = item.Text, Selected = (item.Controller == controller)});
    }
      
    return new MvcHtmlString(menu.ToHtmlString());

    Sorry, still transitioning from Telerik.Mvc...

    Thanks,
    Chris
    Kendo MVC Version: v4.0.30319
  2. Chris
    Chris avatar
    27 posts
    Member since:
    May 2010

    Posted 31 Jul 2012 Link to this post

    Figured it out.  It appears the problem occurs before the rendering.  The property HighlightPath is on by default and does not appear to work in this extension.  It does prevent Selected from being set if on the current controller/action though, so I had to set HighlightPath to false and it seems to work.
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 31 Jul 2012 Link to this post

    Hello Chris,

     
    By design the Menu will select the the menu item which points to the current controller/action. Here is a screencast which shows this behavior. This functionality is turned on by default and you can stop it using the .HighlightPath(false) method. Actually the Kendo Menu behaves in the same way as the Telerik Extensions for ASP.NET MVC. If you need to select the menu items manually I will suggest you turn off the "highlight path" functionality.

    Regards,
    Georgi Krustev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Chris
    Chris avatar
    27 posts
    Member since:
    May 2010

    Posted 31 Jul 2012 Link to this post

    Thanks for the reply.  I agree, turning HightlightPath(false) seems to be the best approach.  I know HighlightPath(true) does work normally, but for some reason it doesn't seem to be working when you create the menu in c#.  I'm not using a sitemap, but i wouldn't think that causes the problem.
  6. S
    S avatar
    15 posts
    Member since:
    Apr 2012

    Posted 07 Feb 2013 Link to this post

    I am also having highlighting the menu and sub menu on Kendo for MVC. This doesn't seem to happen automatically and my workaround has always been using jQuery to add "k-state-highlight" to active menu and submenu.

    I think it's unnecessary (and it should not need) to add jQuery code to add k-state-highlight or overriding k-state-highlight in CSS in order to get the highlighting works. I start to wonder if this is a bug? If so, where can I report this?

    Or maybe even better, you can provide us with jsFiddle or jsBin case to show this is not a bug.

    EDIT
    Here's my screencast:
    http://www.screencast.com/t/x89x3xT5ZY3v

    First is showing that sub menu highlighting is working. Notice the URL in my chrome browser shows the same URL as in highlighted sub menu.
    However, the second menu (stand-alone, no sub menu) has exact same URL but is not highlighted. The code for this second menu can be seen on source of the same screencast
  7. S
    S avatar
    15 posts
    Member since:
    Apr 2012

    Posted 07 Feb 2013 Link to this post

    Please see my updated Screencast:
    http://www.screencast.com/t/x89x3xT5ZY3v
  8. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 12 Feb 2013 Link to this post

    Hello,

     
    Thank you for drawing our attention to this issue. The problem will be addressed for the Q1 2013 release of Kendo UI.

    Regards,
    Georgi Krustev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  9. Eric
    Eric avatar
    19 posts
    Member since:
    Mar 2008

    Posted 15 Jun 2013 Link to this post

    Hello, this doesn't appear to be fixed in Q1 2013.  I'm using this and the menu item is still not highlighted for me.  Can you confirm whether or not this was addressed?
  10. Eric
    Eric avatar
    19 posts
    Member since:
    Mar 2008

    Posted 16 Jun 2013 Link to this post

    Chris, thanks for the workaround...saved me a lot of time.
Back to Top
UI for ASP.NET MVC is VS 2017 Ready