Custom tag helper not working











up vote
14
down vote

favorite
1












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.AspNetCore.Razor.TagHelpers;
using System;

namespace ToolControlSystem.TagHelpers
{
[HtmlTargetElement("description", Attributes = DescriptionAttributeName, TagStructure = TagStructure.NormalOrSelfClosing)]
public class DescriptionTagHelper : TagHelper
{
private const string DescriptionAttributeName = "asp-for";


[HtmlAttributeName(DescriptionAttributeName)]
public ModelExpression Model { get; set; }

public override void Process(TagHelperContext context, TagHelperOutput output)
{
base.Process(context, output);

var description = GetDescription(Model.ModelExplorer);

output.TagName = "span";
output.TagMode = TagMode.StartTagAndEndTag;
output.Content.SetContent(description);
}

private string GetDescription(ModelExplorer modelExplorer)
{
string description;
description = modelExplorer.Metadata.Placeholder;

if (String.IsNullOrWhiteSpace(description))
{
description = modelExplorer.Metadata.Description;
}

return description;
}
}
}


I drop this in _ViewImports.cshtml: @addTagHelper *, ToolConstrolSystem.TagHelpers



Annnndd... nothing. No intellisense, no tag replacing...



Any ideas?










share|improve this question




























    up vote
    14
    down vote

    favorite
    1












    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.AspNetCore.Razor.TagHelpers;
    using System;

    namespace ToolControlSystem.TagHelpers
    {
    [HtmlTargetElement("description", Attributes = DescriptionAttributeName, TagStructure = TagStructure.NormalOrSelfClosing)]
    public class DescriptionTagHelper : TagHelper
    {
    private const string DescriptionAttributeName = "asp-for";


    [HtmlAttributeName(DescriptionAttributeName)]
    public ModelExpression Model { get; set; }

    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
    base.Process(context, output);

    var description = GetDescription(Model.ModelExplorer);

    output.TagName = "span";
    output.TagMode = TagMode.StartTagAndEndTag;
    output.Content.SetContent(description);
    }

    private string GetDescription(ModelExplorer modelExplorer)
    {
    string description;
    description = modelExplorer.Metadata.Placeholder;

    if (String.IsNullOrWhiteSpace(description))
    {
    description = modelExplorer.Metadata.Description;
    }

    return description;
    }
    }
    }


    I drop this in _ViewImports.cshtml: @addTagHelper *, ToolConstrolSystem.TagHelpers



    Annnndd... nothing. No intellisense, no tag replacing...



    Any ideas?










    share|improve this question


























      up vote
      14
      down vote

      favorite
      1









      up vote
      14
      down vote

      favorite
      1






      1





      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.AspNetCore.Razor.TagHelpers;
      using System;

      namespace ToolControlSystem.TagHelpers
      {
      [HtmlTargetElement("description", Attributes = DescriptionAttributeName, TagStructure = TagStructure.NormalOrSelfClosing)]
      public class DescriptionTagHelper : TagHelper
      {
      private const string DescriptionAttributeName = "asp-for";


      [HtmlAttributeName(DescriptionAttributeName)]
      public ModelExpression Model { get; set; }

      public override void Process(TagHelperContext context, TagHelperOutput output)
      {
      base.Process(context, output);

      var description = GetDescription(Model.ModelExplorer);

      output.TagName = "span";
      output.TagMode = TagMode.StartTagAndEndTag;
      output.Content.SetContent(description);
      }

      private string GetDescription(ModelExplorer modelExplorer)
      {
      string description;
      description = modelExplorer.Metadata.Placeholder;

      if (String.IsNullOrWhiteSpace(description))
      {
      description = modelExplorer.Metadata.Description;
      }

      return description;
      }
      }
      }


      I drop this in _ViewImports.cshtml: @addTagHelper *, ToolConstrolSystem.TagHelpers



      Annnndd... nothing. No intellisense, no tag replacing...



      Any ideas?










      share|improve this question















      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.AspNetCore.Razor.TagHelpers;
      using System;

      namespace ToolControlSystem.TagHelpers
      {
      [HtmlTargetElement("description", Attributes = DescriptionAttributeName, TagStructure = TagStructure.NormalOrSelfClosing)]
      public class DescriptionTagHelper : TagHelper
      {
      private const string DescriptionAttributeName = "asp-for";


      [HtmlAttributeName(DescriptionAttributeName)]
      public ModelExpression Model { get; set; }

      public override void Process(TagHelperContext context, TagHelperOutput output)
      {
      base.Process(context, output);

      var description = GetDescription(Model.ModelExplorer);

      output.TagName = "span";
      output.TagMode = TagMode.StartTagAndEndTag;
      output.Content.SetContent(description);
      }

      private string GetDescription(ModelExplorer modelExplorer)
      {
      string description;
      description = modelExplorer.Metadata.Placeholder;

      if (String.IsNullOrWhiteSpace(description))
      {
      description = modelExplorer.Metadata.Description;
      }

      return description;
      }
      }
      }


      I drop this in _ViewImports.cshtml: @addTagHelper *, ToolConstrolSystem.TagHelpers



      Annnndd... nothing. No intellisense, no tag replacing...



      Any ideas?







      c# asp.net-core model asp.net-core-tag-helpers






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 11 at 22:47









      Camilo Terevinto

      17.6k63464




      17.6k63464










      asked Jan 15 at 22:23









      Matthew Goulart

      993723




      993723
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          38
          down vote



          accepted










          You need to provide only assembly name in the view imports file.



          _ViewImports.cshtml: 

          @addTagHelper *, ToolConstrolSystem





          share|improve this answer



















          • 5




            This was really annoying. Thanks for the answear.
            – Edgar Salazar
            Apr 6 at 16:52






          • 4




            Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
            – Mikhail
            Apr 21 at 10:17






          • 2




            Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
            – qJake
            Jun 12 at 20:54










          • The assembly name!! I had the namespace. 3 hours lost until I read this.
            – Alpha75
            Nov 28 at 11:54


















          up vote
          3
          down vote













          See Managing Tag Helper scope



          @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
          @addTagHelper *, AuthoringTagHelpers


          The code above uses the wildcard syntax ("*") to specify that all Tag Helpers in the specified assembly (Microsoft.AspNetCore.Mvc.TagHelpers) will be available to every view file in the Views directory or sub-directory.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48271514%2fcustom-tag-helper-not-working%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            38
            down vote



            accepted










            You need to provide only assembly name in the view imports file.



            _ViewImports.cshtml: 

            @addTagHelper *, ToolConstrolSystem





            share|improve this answer



















            • 5




              This was really annoying. Thanks for the answear.
              – Edgar Salazar
              Apr 6 at 16:52






            • 4




              Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
              – Mikhail
              Apr 21 at 10:17






            • 2




              Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
              – qJake
              Jun 12 at 20:54










            • The assembly name!! I had the namespace. 3 hours lost until I read this.
              – Alpha75
              Nov 28 at 11:54















            up vote
            38
            down vote



            accepted










            You need to provide only assembly name in the view imports file.



            _ViewImports.cshtml: 

            @addTagHelper *, ToolConstrolSystem





            share|improve this answer



















            • 5




              This was really annoying. Thanks for the answear.
              – Edgar Salazar
              Apr 6 at 16:52






            • 4




              Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
              – Mikhail
              Apr 21 at 10:17






            • 2




              Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
              – qJake
              Jun 12 at 20:54










            • The assembly name!! I had the namespace. 3 hours lost until I read this.
              – Alpha75
              Nov 28 at 11:54













            up vote
            38
            down vote



            accepted







            up vote
            38
            down vote



            accepted






            You need to provide only assembly name in the view imports file.



            _ViewImports.cshtml: 

            @addTagHelper *, ToolConstrolSystem





            share|improve this answer














            You need to provide only assembly name in the view imports file.



            _ViewImports.cshtml: 

            @addTagHelper *, ToolConstrolSystem






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 22 at 2:30

























            answered Jan 16 at 0:39









            Anuraj

            12.7k33663




            12.7k33663








            • 5




              This was really annoying. Thanks for the answear.
              – Edgar Salazar
              Apr 6 at 16:52






            • 4




              Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
              – Mikhail
              Apr 21 at 10:17






            • 2




              Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
              – qJake
              Jun 12 at 20:54










            • The assembly name!! I had the namespace. 3 hours lost until I read this.
              – Alpha75
              Nov 28 at 11:54














            • 5




              This was really annoying. Thanks for the answear.
              – Edgar Salazar
              Apr 6 at 16:52






            • 4




              Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
              – Mikhail
              Apr 21 at 10:17






            • 2




              Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
              – qJake
              Jun 12 at 20:54










            • The assembly name!! I had the namespace. 3 hours lost until I read this.
              – Alpha75
              Nov 28 at 11:54








            5




            5




            This was really annoying. Thanks for the answear.
            – Edgar Salazar
            Apr 6 at 16:52




            This was really annoying. Thanks for the answear.
            – Edgar Salazar
            Apr 6 at 16:52




            4




            4




            Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
            – Mikhail
            Apr 21 at 10:17




            Wow, that should be at least (!) in bold in documentation. Spent a few hours too guessing what did go wrong.
            – Mikhail
            Apr 21 at 10:17




            2




            2




            Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
            – qJake
            Jun 12 at 20:54




            Documentation makes it look like it's a namespace, not an assembly name. *faceplam*
            – qJake
            Jun 12 at 20:54












            The assembly name!! I had the namespace. 3 hours lost until I read this.
            – Alpha75
            Nov 28 at 11:54




            The assembly name!! I had the namespace. 3 hours lost until I read this.
            – Alpha75
            Nov 28 at 11:54












            up vote
            3
            down vote













            See Managing Tag Helper scope



            @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
            @addTagHelper *, AuthoringTagHelpers


            The code above uses the wildcard syntax ("*") to specify that all Tag Helpers in the specified assembly (Microsoft.AspNetCore.Mvc.TagHelpers) will be available to every view file in the Views directory or sub-directory.






            share|improve this answer

























              up vote
              3
              down vote













              See Managing Tag Helper scope



              @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
              @addTagHelper *, AuthoringTagHelpers


              The code above uses the wildcard syntax ("*") to specify that all Tag Helpers in the specified assembly (Microsoft.AspNetCore.Mvc.TagHelpers) will be available to every view file in the Views directory or sub-directory.






              share|improve this answer























                up vote
                3
                down vote










                up vote
                3
                down vote









                See Managing Tag Helper scope



                @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
                @addTagHelper *, AuthoringTagHelpers


                The code above uses the wildcard syntax ("*") to specify that all Tag Helpers in the specified assembly (Microsoft.AspNetCore.Mvc.TagHelpers) will be available to every view file in the Views directory or sub-directory.






                share|improve this answer












                See Managing Tag Helper scope



                @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
                @addTagHelper *, AuthoringTagHelpers


                The code above uses the wildcard syntax ("*") to specify that all Tag Helpers in the specified assembly (Microsoft.AspNetCore.Mvc.TagHelpers) will be available to every view file in the Views directory or sub-directory.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jun 13 at 20:08









                RickAndMSFT

                10.6k53954




                10.6k53954






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48271514%2fcustom-tag-helper-not-working%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Berounka

                    Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

                    Sphinx de Gizeh