CodexBloom - Programming Q&A Platform

Visual Studio 2022 - how to to Resolve The 'Include' Directive in Razor Pages with Custom Tag Helpers

👀 Views: 93 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-14
asp.net-core razor-pages tag-helpers visual-studio C#

I'm testing a new approach and I'm working on a project and hit a roadblock..... I'm working with a frustrating scenario while working on an ASP.NET Core Razor Pages project in Visual Studio 2022. I have created a custom tag helper that is intended to format some text in my views. However, when I try to use this tag helper in my razor page, I get the behavior: `The 'myTagHelper' tag is not recognized.` I've followed the steps to create the tag helper, and I believe I've set everything up correctly. Here's how my tag helper looks: ```csharp using Microsoft.AspNetCore.Razor.TagHelpers; [HtmlTargetElement("myTagHelper")] public class MyTagHelper : TagHelper { public string Text { get; set; } public override void Process(TagHelperContext context, TagHelperOutput output) { output.Content.SetHtmlContent($"<strong>{Text}</strong>"); } } ``` In my `_ViewImports.cshtml`, I've added the namespace where my tag helper resides: ```razor @using MyProject.TagHelpers ``` Despite this, the behavior continues. I've also ensured that I have the correct NuGet packages installed, and I've tried cleaning and rebuilding the solution multiple times. The scenario happens only with this specific tag helper; other built-in tag helpers work without any problems. Could there be an scenario with the way I'm defining or using the tag helper? Are there any common pitfalls with tag helpers in Razor Pages that I might be overlooking? Any insights or guidance would be greatly appreciated! For context: I'm using C# on macOS. This is part of a larger service I'm building. My team is using C# for this mobile app. What's the correct way to implement this?