This is a migrated thread and some comments may be shown as answers.

Set Current Menu Item to Selected

8 Answers 798 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 30 Jul 2012, 06:27 PM
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

8 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 31 Jul 2012, 02:17 PM
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.
0
Georgi Krustev
Telerik team
answered on 31 Jul 2012, 02:53 PM
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!
0
Chris
Top achievements
Rank 1
answered on 31 Jul 2012, 03:00 PM
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.
0
S
Top achievements
Rank 1
answered on 07 Feb 2013, 07:58 PM
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
0
S
Top achievements
Rank 1
answered on 07 Feb 2013, 09:01 PM
Please see my updated Screencast:
http://www.screencast.com/t/x89x3xT5ZY3v
0
Georgi Krustev
Telerik team
answered on 12 Feb 2013, 12:07 PM
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!
0
Eric
Top achievements
Rank 1
answered on 15 Jun 2013, 08:58 PM
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?
0
Eric
Top achievements
Rank 1
answered on 16 Jun 2013, 07:26 PM
Chris, thanks for the workaround...saved me a lot of time.
Tags
Menu
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Georgi Krustev
Telerik team
S
Top achievements
Rank 1
Eric
Top achievements
Rank 1
Share this question
or