It's relatively easy to create a custom TagHelper in C# and use it inside a CSHTML view.
- First, let's create a VerticalMenuTagHelper class, which inherits from TagHelper. We indicate, by using the HtmlTargetElement attribute above the class, that we will use vmenu as the HTML element name to use this TagHelper in a view :
namespace R3.TagHelpers { [HtmlTargetElement("vmenu")] public class VerticalMenuTagHelper : TagHelper { public List<MenuElement> Elements { get; set; } public override void Process( TagHelperContext context, TagHelperOutput output) { output.TagName = "section"; string menuElements = "<ul>"; foreach (var e in Elements) { menuElements += $@"<li><ahref='{e.Controller}/{e.Action}'><strong>{e.Name}</strong> ...