'Call to TagHelper.Process(context, output) not creating Attributes of custom Anchor Tag Helper

I'm building a multi culture application and have implemented a custom anchor tag helper to add culture as route value.

The Custom Tag Helper seems to render as expected only in partial views, but not in the Razor Pages it self or a View Component.

Update

I have investigated the bug further. Debuging have identified to issues possibly being related to base.Process(context, output);. Values passed in context look correct, wheres as output does not change as expected. output holds "class" in attributes and not "href", etc. thus "culture" is also missing from "href"

Custom Tag Helper

[HtmlTargetElement("a", Attributes = ActionAttributeName)]
[HtmlTargetElement("a", Attributes = ControllerAttributeName)]
[HtmlTargetElement("a", Attributes = AreaAttributeName)]
[HtmlTargetElement("a", Attributes = PageAttributeName)]
[HtmlTargetElement("a", Attributes = PageHandlerAttributeName)]
[HtmlTargetElement("a", Attributes = FragmentAttributeName)]
[HtmlTargetElement("a", Attributes = HostAttributeName)]
[HtmlTargetElement("a", Attributes = ProtocolAttributeName)]
[HtmlTargetElement("a", Attributes = RouteAttributeName)]
[HtmlTargetElement("a", Attributes = RouteValuesDictionaryName)]
[HtmlTargetElement("a", Attributes = RouteValuesPrefix + "*")]
public class CultureAnchorTagHelper : AnchorTagHelper
{
    private const string ActionAttributeName = "asp-action";
    private const string ControllerAttributeName = "asp-controller";
    private const string AreaAttributeName = "asp-area";
    private const string PageAttributeName = "asp-page";
    private const string PageHandlerAttributeName = "asp-page-handler";
    private const string FragmentAttributeName = "asp-fragment";
    private const string HostAttributeName = "asp-host";
    private const string ProtocolAttributeName = "asp-protocol";
    private const string RouteAttributeName = "asp-route";
    private const string RouteValuesDictionaryName = "asp-all-route-data";
    private const string RouteValuesPrefix = "asp-route-";
    
    public CultureAnchorTagHelper(IHtmlGenerator generator) : base(generator) { }
    
    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
        RouteValues["culture"] = CultureInfo.CurrentCulture.Name;

        base.Process(context, output);
    }
}

\Pages\_ViewImports.cshtml \Pages\Shared\ (here partial views are stored \Pages\Shared\Components\ (View Components are stored in sub folders)

_ViewImports.cstml

@using MyApp.Web
@namespace MyApp.Web.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@removeTagHelper Microsoft.AspNetCore.Mvc.TagHelpers.AnchorTagHelper, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper CultureAnchorTagHelper, MyApp.Web.TagHelpers
@addTagHelper *, MyApp Web

It should be noted that View Component tag helpers are working as expected and the custom tag helpers is also invoked as expected.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source