Custom tag helper not working

前端 未结 8 1392
抹茶落季
抹茶落季 2021-02-03 19:11

I followed a few guides on creating a custom tag helper for ASP Core.

This is my helper:

using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.Asp         


        
相关标签:
8条回答
  • 2021-02-03 19:43

    I had the same problem, but it was the result of a rogue, accidental semi-colon at the end of the @addTagHelper line.

    I had:

    @addTagHelper *, ToolConstrolSystem;

    Instead of:

    @addTagHelper *, ToolConstrolSystem

    While the solution will build and run fine, the tag helper will not work if the @addTagHelper line contains a semi-colon.

    0 讨论(0)
  • 2021-02-03 19:44

    Another thing to check if you're finding you can't set your content with calls like:

    output.Content.AppendHtml("<tags...>");
    output.Content.SetHtmlContent("<tags...>");
    

    Is to check that you didn't use your tag helper as an empty/void element, e.g.:

    <my-tag-helper attr="value" />
    

    To add content the tag helper must have a closing tag:

    <my-tag-helper attr="value"></my-tag-helper>
    
    0 讨论(0)
提交回复
热议问题