在 _ViewImports.cshtml
中添加 @addTagHelper *, Cnblogs.Web
之后,所有 razor view 中没有显示闭合的 <img>
标签在 build 时都报错:
Found a malformed 'img' tag helper. Tag helpers must have a start and end tag or be self closing.
请求如何解决这个问题?
是下面的 tag helper 引起的,只要是 HtmlTargetElement
指向的标签,都会有这个问题
[HtmlTargetElement("img")]
[HtmlTargetElement("button")]
[HtmlTargetElement("script")]
[HtmlTargetElement("link")]
[HtmlTargetElement("div")]
[HtmlTargetElement("a")]
[HtmlTargetElement("p")]
[HtmlTargetElement(Attributes = "asp-visible")]
public class VisibleTagHelper : TagHelper
{
[HtmlAttributeName("asp-visible")]
public bool IsVisible { get; set; } = true;
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (!IsVisible)
{
output.SuppressOutput();
}
}
}
HtmlTargetElement 有个 TagStructure 属性,设置为 WithoutEndTag
可以解决
[HtmlTargetElement("img", TagStructure = TagStructure.WithoutEndTag)]