I've created a dropdown menu, and I'm trying remove the "link" from the main drop down item. (The menuitem that is hovered, to activate the dropdown)
Furthermore, I'm trying to highlight the main item, and the selected item in the dropdown. I use class="@(CurrentPage.Id == item.Id ? "current_page_item" : null)" to highlight the current page.
Is there an elegant way to do it? When I try coding it, it gets a bit too messy, and I thought there should be a more cleaner way to solve it.
I't works great with the (node.Level == 1) - the code is much simpler.
Do you have any idea how to solve the highlight part of the question? and how to make the menuitem with the dropdown "nonlinkable". So its only the children in the dropdown menu, that is clickable?
I've tried the code example you gave me, but it didn't work as intended.
I don't know if I asked the right question. But to make it clearer, I'm trying to highlight the menu item that has one of its "children" activated, and highlight the activated child.
Severity Code Description Project File Line Suppression State
Error CS1973 'IPublishedContent' has no applicable method named 'IsDescendantOrSelf' but appears to have an extension method by that
name. Extension methods cannot be dynamically dispatched. Consider
casting the dynamic arguments or calling the extension method without
the extension method
syntax.
ViewsPartialsumbTopNavigation.cshtml
Do you know how to casting the dynamic arguments or call the extensions method without the extension method syntax?
DropDown with highlights and removed mainlink
Hi All
I've created a dropdown menu, and I'm trying remove the "link" from the main drop down item. (The menuitem that is hovered, to activate the dropdown)
Furthermore, I'm trying to highlight the main item, and the selected item in the dropdown. I use
class="@(CurrentPage.Id == item.Id ? "current_page_item" : null)"
to highlight the current page.Is there an elegant way to do it? When I try coding it, it gets a bit too messy, and I thought there should be a more cleaner way to solve it.
The complete partial code:
Hi Anders
If I understood the logic right, it should work:
Just check level of current node in Traverse helper, and you don't need TraverseDescendants
Thanks,
Alex
Hi Alex
Thanks for answering my post.
I't works great with the
(node.Level == 1)
- the code is much simpler.Do you have any idea how to solve the highlight part of the question? and how to make the menuitem with the dropdown "nonlinkable". So its only the children in the dropdown menu, that is clickable?
Thanks :)
Hi Anders
Try to use this code for "nonlinkable" items:
Hi Alex
Thanks for answering, again :)
Your example worked perfectly when I switched the javascript:void(0) and @item.Url.
So the if statement looks like:
Why use javascript:void(0) instead of just # - Is it better practice?
Because if you press on link with # it will move your browser window to the top of the page, I don't like it
Of course you can use some js handler for it, but it's easier to use javascript:void(0)
Alex
Makes sense !
Thanks for the tip !
Code for highlighting the item:
As I read it, I was supposed to switch the
CurrentPage.Id == item.Id
withitem.Path.Contains(CurrentPage.Id)
The highlighting code throws an error:
The best overloaded method match for 'string.Contains(string)' has some invalid arguments
Guess it can't find the
item.Path.Contains
Do you have any ideas what the problem is here?
Hi Anders
I rewrote your code to strongly typed, try it:
Hi Anders
Did you try latest code snippet?
Alex
Hi Alex
Sorry for not answering to your reply.
I've tried the code example you gave me, but it didn't work as intended.
I don't know if I asked the right question. But to make it clearer, I'm trying to highlight the menu item that has one of its "children" activated, and highlight the activated child.
Example:
((( means highlighted )))
Hope the example helps, otherwise don't hesitate to ask :)
Hi Anders
Thanks, yes, I understood what did you mean.
Try this code:
Hi Alex
The following error occurs:
Do you know how to casting the dynamic arguments or call the extensions method without the extension method syntax?
is working on a reply...