I'm trying to create a custom tag helper in MVC 6 but can't make it work.
Here is my demo tag helper class defined in the web app project.
namespace Microsoft.AspNet.Mvc.TagHelpers
{
[TargetElement("demo", Attributes = CustomAttributeName)]
public class DemoTagHelper : TagHelper
{
private const string CustomAttributeName = "asp-custom";
[HtmlAttributeName(CustomAttributeName)]
public string Custom { get; set; }
public string Value { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "div";
output.Attributes["foo"] = "bar";
}
}
}
This is how I use it in my views:
<demo asp-custom="hello world!">
Please work this time :)
</demo>
I tried many things. Removed TargetElement
attribute or changed the namespace. Nothing changes...
The result is still same.
By the way my Microsoft.AspNet.Mvc.TagHelpers version is 6.0.0-beta4.
Maybe I have to register my tag helper somewhere? I looked into MVC source codes and they haven't referenced their own tag helpers anywhere. So I think there is no registration needed.
Where is the problem here?