I want to port a very old pdf processing application to .Net and in the process convert handelbars templates to Razor.
I am scratching my head on why a TagHelper is not being picked up.
namespace NemoPdfNet.TagHelpers
{
public class LogoTagHelper : TagHelper
{
public required string Brand { get; set; }
public required Dictionary<string, string> Logos { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (!string.IsNullOrEmpty(Brand) && Brand == "whitelabel")
output.SuppressOutput();
else
{
output.TagName = "img";
if (!Logos.ContainsKey(Brand))
{
output.Attributes.SetAttribute("src", Logos["default"]);
output.Attributes.SetAttribute("class", "pdf-header-logo default");
}
else
{
output.Attributes.SetAttribute("src", Logos[Brand]);
output.Attributes.SetAttribute("class", "pdf-header-logo " + Brand);
}
}
}
}
}
ViewImports.cshtml
@using NemoPdfNet
@using NemoPdfNet.Models
@using NemoPdfNet.Requests
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, NemoPdfNet.TagHelpers
If I now want to use this, it does not get resolved:
@if (!string.IsNullOrEmpty(Model.Brand))
{
<partial name="_LogoPartial"
model="new NemoPdfNet.Models.LogoViewModel { Brand = Model.Brand, Logos = Model.Logos }" />
<logo brand="Model.Brand" logos="Model.Logos"></logo>
}
While the partial is working as expected and delivers the functionality, the logo taghelper gets rendered as
<logo brand="default" logos="System.Collections.Generic.Dictionary`2[System.String,System.String]"></logo>
What am I doing wrong?