This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
Routes values are being added in duplicate #3250
Closed
Description
Hello,
I created a TagHelper and needed to access the current route so I ended up with:
[TargetElement("a", Attributes = RouteHasName)]
public class RouteActiveTagHelper : TagHelper {
private const String RouteHasName = "route-has";
private IActionContextAccessor _actionContextAccessor;
private IUrlHelper _urlHelper;
[HtmlAttributeName(RouteHasName)]
public String RouteHas { get; set; }
public RouteActiveTagHelper(IActionContextAccessor actionContextAccessor, IUrlHelper urlHelper) {
_actionContextAccessor = actionContextAccessor;
_urlHelper = urlHelper;
} // RouteActiveTagHelper
public override void Process(TagHelperContext context, TagHelperOutput output) {
var values = _actionContextAccessor.ActionContext.RouteData.Values;
String route = _urlHelper.RouteUrl(values.Distinct());
// Removed remaining code for sake of simplicity
} // Process
} // RouteActiveTagHelper
When I create the route I get the error "ArgumentException: An item with the same key has already been added." on every route which is defined using Attribute Routing.
To fix this I needed to apply Distinct to values before creating a route.
Is there any reason for having duplicated objects in route values? Is this a bug?
If this is the expected result is there a better way to get the current route values?
Note: I get the same error using ViewContext ...
Thank You,
Miguel