未呈现活动路由自定义 TagHelper

Active route custom TagHelper is not rendered

我创建了一个具有属性 'is-active-route' 的新标签助手 (ActiveRouteTagHelper)。但是,在任何 Razor 页面上使用此属性时,都不会调用辅助进程。该应用程序在 .NET Core 2.2 上 运行。

我已确保 @addTagHelper 引用已添加到 _ViewImports 并且 class 和覆盖都是 public.

_ViewImports.cshtml

@using SIRS_Web
@using SIRS_Web.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, SIRS_Web

ActiveRouteTagHelper.cs

namespace SIRS_Web.TagHelpers
{
    [HtmlTargetElement(Attributes = "is-active-route")]
    public class ActiveRouteTagHelper : TagHelper
    {
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.Attributes.RemoveAll("is-active-route");
        }
    }

_Layout.cshtml

    ...
    <a is-active-route href="#">Link</a>
    ...

我已经在流程覆盖的第一行添加了一个断点,但从未达到这一点,并且属性 is-active-route 出现在页面中。

@addTagHelper 指令不采用名称空间,它采用 程序集名称 。那将是你的问题。

请抽空阅读以下内容link:

https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/authoring?view=aspnetcore-2.2#a-minimal-tag-helper