本文介绍了自定义标签助手不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遵循了一些有关为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更多推荐
自定义标签助手不起作用
发布评论