Hello this is my tag helper
[HtmlTargetElement("card")]
public class CardTagHelper : TagHelper
{
public string Title { get; set; }
public string Icon { get; set; }
public string Url { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "CardTagHelper";
output.TagMode = TagMode.StartTagAndEndTag;
var preContent = new StringBuilder();
preContent.AppendFormat($@"
<div class='card custom-card'>
<div class='card-header'>
<div class='card-title'>");
if (Url != null)
{
preContent.AppendFormat($@"
<a asp-for='{Url}'>
<div class='float-left return'>
<i class='fas fa-arrow-alt-circle-left fa-lg'></i>
</div>
</a>");
}
preContent.AppendFormat($@"<i class='{Icon}'></i>
{Title}
</div>
</div>
<div class='card-body'>");
var postContent = new StringBuilder();
postContent.AppendFormat($@"
</div>
<div class='card-footer'>
</div>
</div>");
output.PreContent.SetHtmlContent(preContent.ToString());
output.PostContent.SetHtmlContent(postContent.ToString());
}
}
}
the output is a bootstrap 4 card
<card title="myTitle" icon="myIcon" url="redirectUrl">
// Content here
</card>
my problem is that i would like to use asp-page instead of href on the conditional rendered string for the anchor but when i added it, it had no effect or any clickable.
EDIT
These are my viewimports, as suggested i tried include my custom helper before the Asp.Net Core
@using MyProject
@namespace MyProject.Pages
@addTagHelper *, MyProject
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
_ViewImports.cshtml
. That means the built-in helpers have already ran before this code even existed. Referencing your library first should resolve that. That said, it's better to not rely on other taghelpers exactly for this reason: it's too easy to break things. – Chris Pratt