自定义标签助手不起作用

编程入门 行业动态 更新时间:2024-10-10 09:19:15
本文介绍了自定义标签助手不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遵循了一些有关为ASP Core创建自定义标签帮助程序的指南.

I followed a few guides on creating a custom tag helper for ASP Core.

这是我的助手:

using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Razor.TagHelpers; using System; namespace ToolControlSystem.TagHelpers { [HtmlTargetElement("description", Attributes = DescriptionAttributeName, TagStructure = TagStructure.NormalOrSelfClosing)] public class DescriptionTagHelper : TagHelper { private const string DescriptionAttributeName = "asp-for"; [HtmlAttributeName(DescriptionAttributeName)] public ModelExpression Model { get; set; } public override void Process(TagHelperContext context, TagHelperOutput output) { base.Process(context, output); var description = GetDescription(Model.ModelExplorer); output.TagName = "span"; output.TagMode = TagMode.StartTagAndEndTag; output.Content.SetContent(description); } private string GetDescription(ModelExplorer modelExplorer) { string description; description = modelExplorer.Metadata.Placeholder; if (String.IsNullOrWhiteSpace(description)) { description = modelExplorer.Metadata.Description; } return description; } } }

我将其放置在_ViewImports.cshtml中:@addTagHelper *, ToolConstrolSystem.TagHelpers

Annnndd ...没事.没有智能,没有标签替换...

Annnndd... nothing. No intellisense, no tag replacing...

有什么想法吗?

推荐答案

您只需要在视图导入文件中提供程序集名称.

You need to provide only assembly name in the view imports file.

_ViewImports.cshtml:  @addTagHelper *, ToolConstrolSystem

更多推荐

自定义标签助手不起作用

本文发布于:2023-11-02 06:03:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1551570.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   不起作用   助手   标签

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!