2 years ago
#52395

Andi AR
How to implement custom taghelper in .NET MAUI BLAZOR project
I tried to implement a custom TAGhelper in .NET MAUI blazor project but not working. Seems viewimport is not properly registered. Custom component not rendering & breakpoint also not hitting.
Below steps, I followed.
Installed Microsoft.AspNetCore.Mvc.TagHelpers & Microsoft.AspNetCore.Mvc.TagHelpers via nugget.
Implemented simple custom taghelper cs file as mentioned below,
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace Sitecore.MAUI.Service.RenderingEngine.TagHelpers
{
[HtmlTargetElement("sc-placeholder")]
public class PlaceholderTagHelper : TagHelper
{
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.Content.SetContent("Custom sc component");
}
}
}
- Created Viewimport.cshtml inside a shared folder. As well I tried to create a view folder and placed it. Both not working. below lines inside the viewport.
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers"
@addTagHelper "*, Sitecore.MAUI.Service.RenderingEngine.TagHelpers"
- I tried using viewimport.razor , instead of cshtml but it's throwing an error. So I kept it as cshtml.
The directives @addTagHelper, @removeTagHelper and @tagHelperPrefix are not valid in a component document. Use '@using ' directive instead. c:***\Src\Sitecore.Net.MAUI.Blazor.Client\Shared_ViewImports.razor
- In the main layout.razor i placed the component as shown below,
@inherits LayoutComponentBase
<div class="page">
<div class="sidebar">
<NavMenu />
</div>
<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/" target="_blank">About</a>
</div>
<article class="content px-4">
<sc-placeholder name="myproject-main"></sc-placeholder>
@Body
</article>
</main>
</div>
asp.net-core
tag-helpers
asp.net-core-tag-helpers
maui
maui-blazor
0 Answers
Your Answer