It's because you're doing the conditional outside of the loop. It's only being checked once against the current page instead for each item in the navigation.
var cssClass = root.Id == Model.Content.Id? "active": string.Empty;
Basically is adding up to: "If the user is on the homepage/root set cssClass equal to active otherwise set it to empty".
In your loop you'll want to do something like:
var cssClass = page.Id == Model.Content.Id? "active": string.Empty;
CSS navbar - all styles are 'active', or all are empty
Is it only cssClasss that needs to change (code follow in next comment)?
Exactly how does the
root.Id == Model.Content.Id? "active": string.Empty;work?Someone who sees why all CSS class is "active" on the Home page, but "" (empty) for all other links (Level 2 / subpages) in the menu?
Have tried also with different names for CSS-variabels for all li-classes, but the result is the same.
Example:
Anybody who has a solution?
OK, found it. Not
root.Id == Model.Content.Idin Level 2 subpages, butpage.Id == Model.Content.Idof course.It's because you're doing the conditional outside of the loop. It's only being checked once against the current page instead for each item in the navigation.
Basically is adding up to: "If the user is on the homepage/root set cssClass equal to active otherwise set it to empty".
In your loop you'll want to do something like:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.