SuppressOutput()无法与其他WithoutEndTag TagHelper结合使用

时间:2019-06-14 10:14:19

标签: c# asp.net-core

我从Microsoft文档中的ConditionTagHelper开始 https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/authoring#condition-tag-helper 并添加了我自己的

[HtmlTargetElement(Attributes = nameof(Disabled), TagStructure = TagStructure.WithoutEndTag)]
public class DisabledTagHelper : TagHelper
{
    public bool Disabled { get; set; }
    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
        if (Disabled) output.Attributes.Add("disabled", "disabled");
    }
}

现在,<input>将被禁止?

<input disabled="true" condition="false" value="disabled && suppressed">

<fieldset></fieldset>将被删除,但其内容不会?

<fieldset disabled="true" condition="false"><input value="disabled && suppressed"></fieldset>

我怎么了?


不是最佳解决方法:

  • TagStructure.WithoutEndTag实现中删除所有TagHelper
  • 在不带有结束标签的所有标签中添加自闭合结束标签/>(否则:找到格式错误的“输入”标签帮助器。标签帮助器必须具有开始和结束标签,或者必须是自闭合的。

(我不喜欢这种解决方法,因为添加/删除TagHelper会迫使我添加/删除自动关闭的结束标签。)

0 个答案:

没有答案