nav: ActivePage is case-insensitive on controller/action
Fixes inactive Blogspot link: RouteData keeps the C# class name "BlogSpot" while asp-controller matches "Blogspot" case-insensitively.
This commit is contained in:
parent
44fec4c8e5
commit
990608d4f7
1 changed files with 10 additions and 6 deletions
|
|
@ -24,21 +24,25 @@ namespace Yavsc.Server.Helpers
|
||||||
var currentAction = route["action"] as string;
|
var currentAction = route["action"] as string;
|
||||||
|
|
||||||
// Normalize: empty or "Home" + ("Index" or null) both target the site root.
|
// Normalize: empty or "Home" + ("Index" or null) both target the site root.
|
||||||
|
// Compare case-insensitively because asp-controller tag helpers resolve
|
||||||
|
// controller names case-insensitively, while RouteData["controller"] holds
|
||||||
|
// the actual class name (e.g. "BlogSpot" vs an URL segment "Blogspot").
|
||||||
|
var cmp = StringComparison.OrdinalIgnoreCase;
|
||||||
bool isHome = string.IsNullOrEmpty(controller)
|
bool isHome = string.IsNullOrEmpty(controller)
|
||||||
|| (string.Equals(controller, "Home", StringComparison.Ordinal)
|
|| (string.Equals(controller, "Home", cmp)
|
||||||
&& (action == null || string.Equals(action, "Index", StringComparison.Ordinal)));
|
&& (action == null || string.Equals(action, "Index", cmp)));
|
||||||
|
|
||||||
bool isCurrent;
|
bool isCurrent;
|
||||||
if (isHome)
|
if (isHome)
|
||||||
{
|
{
|
||||||
isCurrent = string.IsNullOrEmpty(currentController)
|
isCurrent = string.IsNullOrEmpty(currentController)
|
||||||
|| string.Equals(currentController, "Home", StringComparison.Ordinal)
|
|| string.Equals(currentController, "Home", cmp)
|
||||||
&& (currentAction == null || string.Equals(currentAction, "Index", StringComparison.Ordinal));
|
&& (currentAction == null || string.Equals(currentAction, "Index", cmp));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
isCurrent = string.Equals(currentController, controller, StringComparison.Ordinal)
|
isCurrent = string.Equals(currentController, controller, cmp)
|
||||||
&& (action == null || string.Equals(currentAction, action, StringComparison.Ordinal));
|
&& (action == null || string.Equals(currentAction, action, cmp));
|
||||||
}
|
}
|
||||||
|
|
||||||
return isCurrent
|
return isCurrent
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue