the taghelper do not rendered?

mc 5,141 Reputation points
2023-01-28T01:27:55.3233333+00:00
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace tag.Components
{
    [HtmlTargetElement("pagination", TagStructure = TagStructure.WithoutEndTag)]
    public class PaginationTagHelper : TagHelper
    {
        [HtmlAttributeName("page-index")]
        public int PageIndex { get; set; }

        public string aspFor { get; set; }


        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.Attributes.SetAttribute("class", aspFor);
            output.Content.SetHtmlContent("<div>" + PageIndex + "</div>");
      }
    }
}

in _ViewImports.cshtml

@using tag

@namespace tag.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, tag.Components

in Index.cshtml

<pagination page-index="10" asp-for="data"></pagination>
<Pagination page-index="10" asp-for="data"></Pagination>

but it is not rendered?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,779 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,596 questions
{count} votes

Accepted answer
  1. Xinran Shen - MSFT 2,091 Reputation points
    2023-01-30T06:13:58.0666667+00:00

    Hi 打玻璃, in your _ViewImports.cshtml class, please use:

    @addTagHelper *, tag
    

    instead of

    @addTagHelper *, tag.Components
    

    Then in your PaginationTagHelper class, remove

    [HtmlTargetElement("pagination", TagStructure = TagStructure.WithoutEndTag)]

    Or just remove

    TagStructure = TagStructure.WithoutEndTag

    Now this tag will be rendered in your view:

    enter image description here


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Xinran Shen

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.