Reputation: 1999
I'm trying to make a custom tag helper work in asp-net core 3.0.
using System.Threading.Tasks;
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace MyProject.TagHelpers
{
[HtmlTargetElement("p", Attributes = "markdown")]
[HtmlTargetElement("markdown")]
[OutputElementHint("p")]
public class MarkdownTagHelper : TagHelper
{
public async override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
output.Content.SetHtmlContent("<p>lkajsdlkjasdlkjasd</p>");
}
}
}
_ViewImports.cshtml
:
@using MyProject
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, MyProject
I'm trying to reference <markdown></markdown>
in the TermsConditions.cshtml
file. (Full file:)
<div>
<markdown></markdown>
</div>
But still, the markdown
tag is never replaced when calling that view.
I found many questions, blogs, ..., but nothing worked so far. I checked for the following common mistakes.
Process
What do I have to do in order to make TagHelpers work?
Upvotes: 1
Views: 1859
Reputation: 234
Maybe I'll save someone time.. In my case the AssemblyName
was missing in the current project, so the tag helpers was not applied.
In _ViewImports.cshtml
file should be used this AssemblyName
like:
@using AssemblyName
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, AssemblyName
And don't forget to add these assemblies:
Microsoft.AspNetCore.Mvc.Razor
Microsoft.AspNetCore.Mvc.TagHelpers
Microsoft.AspNetCore.Razor.Runtime
Upvotes: 2
Reputation: 11090
Everything looks right, from the available information. So I suspect that this isn't actually your assembly name;
@addTagHelper *, MyProject
Upvotes: 1
Reputation: 13
Doesn't look like you are applying it correctly..
Change
[HtmlTargetElement("p", Attributes = "markdown")]
[HtmlTargetElement("markdown")]
[OutputElementHint("p")]
To
[HtmlTargetElement("markdown")]
In your original code, you would need to do something like <p markdown="some text"></p>
Upvotes: 0