I am trying to create a special tag helper in MVC 6 but cannot make it work.
Here is my helper class for the demo tag defined in a web application 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"; } } }
Here's how I use it in my views:
<demo asp-custom="hello world!"> Please work this time :) </demo>
I've tried a lot. TargetElement attribute TargetElement or namespace changed. Nothing changes ... The result is still the same.
By the way, my version of Microsoft.AspNet.Mvc.TagHelpers is 6.0.0-beta4 .
Maybe I need to register my tag helper somewhere? I looked at the MVC source codes and they never referenced their own tag helpers anywhere. Therefore, I think registration is not required.
Where is the problem?
Yves
source share