Here is my custom tag helper, it renders asp-for as asp-page on browser.... Is there a way i need to refer other tag helpers cuase this way it is not rendering
[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-page='{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());
}
}
}
This is my view import, i changed the order so my custom tag helper was first but didnt change anything
@using MyProject
@namespace MyProject.Pages
@addTagHelper *, MyProject
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Hi. It looks like this is a question about how to use ASP.NET Core. While we do our best to look through all the issues filed here, to get a faster response we suggest posting your questions to StackOverflow using the asp.net-core-mvc tag.
FYI: You're trying to embed a razor content in the output of the Tag Helper, and that's not supported.
FYI: You're trying to embed a razor content in the output of the Tag Helper, and that's not supported.
I see, so there is no workaround for this? I have just been feeding it @Url.Page(""), it does the job but would rather have to just right the path "./Index" or "../Index"
You can simply use the Razor content you have in this tag helper instead of it, wherever you reference it.
Seems like you're just trying to have a reusable razor component - what about using Partial Views for it?
You can simply use the Razor content you have in this tag helper instead of it, wherever you reference it.
Could you show me an example please? I tried add asp-page on it and didn't do anything
Here is the docs article about PartialViews: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/partial?view=aspnetcore-2.2
It does contain an example too
Here is the docs article about PartialViews: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/partial?view=aspnetcore-2.2
It does contain an example too
I don't think partial views will help me in this situation because i need to write content inside, html razor etc...
something i can use in every page as a container for my content
Think about PartialViews as reusable views, which can contain both html and razor content. You can then use the Partial Tag Helper to reference them from different pages/views.