Generating a parent url for an action or controller that is not part of an Area while on a page that is part of an Area causes the parent urls to assume the Area of the current page. This is because IUrlHelper.Action will use the current page's area route value when generating the url even if null is supplied as the RouteValues parameter.
When RouteValues above is null (AreaName not specified on BreadcrumbAttribute), the route value area on the current page is supplied when generating the url.
Looks like node url generating logic needs to explicitly include an empty area in the route values for nodes that do not specify an area. Something like this on BreadcrumbNode constructor:
Current:
if (!string.IsNullOrWhiteSpace(areaName))
{
RouteValues = new
{
area = areaName
};
}
New:
RouteValues = new
{
area = areaName?.Trim() ?? string.Empty
};
This way, for controllers and actions that are not under an Area, the route values will explicitly say { area = string.Empty } so the url helper will generate the url properly. What do you think? My preliminary testing checks out. I'd be glad to make a pull request for this, but wanted to run it by someone else. Thanks!
Generating a parent url for an action or controller that is not part of an Area while on a page that is part of an Area causes the parent urls to assume the Area of the current page. This is because
IUrlHelper.Action
will use the current page's area route value when generating the url even ifnull
is supplied as theRouteValues
parameter.string GetUrl(IUrlHelper urlHelper) => urlHelper.Action(Action, Controller, RouteValues);
When RouteValues above is null (AreaName not specified on
BreadcrumbAttribute
), the route value area on the current page is supplied when generating the url.Looks like node url generating logic needs to explicitly include an empty area in the route values for nodes that do not specify an area. Something like this on
BreadcrumbNode
constructor:Current:
New:
This way, for controllers and actions that are not under an Area, the route values will explicitly say
{ area = string.Empty }
so the url helper will generate the url properly. What do you think? My preliminary testing checks out. I'd be glad to make a pull request for this, but wanted to run it by someone else. Thanks!