1

I'm creating a library of MVC6 TagHelpers for a large project.

I find myself writing certain functionality in these TagHelpers again and again.

I'd like to make a base TagHelper that all the others inherit from to remove all the duplicated code.

The issue is this - suppose I create a base TagHelper as below:

public class BaseTagHelper : TagHelper
{

    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
        //Some implementation...
    }
}

Now, when I go to write a view, I will have intellisense suggesting the taghelper <base>.

Is there any way I can tell intellisense that this isn't a TagHelper I actually want to use, just a base class containing implementation common to other TagHelpers I've created?

1 Answer 1

2

Create it as an abstract class, see some examples in the official MVC Core repo like CacheTagHelperBase

public abstract class BaseTagHelper : TagHelper
{

    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
        //Some base implementation...
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.