【问题标题】:How can I make a TagHelper render only plain text with no parent tag?如何让 TagHelper 只呈现没有父标签的纯文本?
【发布时间】:2020-09-24 14:09:18
【问题描述】:

如何阻止我的 TagHelper 呈现外部标签?

例如我想要类似的东西:

<title>
    <translate>LoginPageTitle</translate>
</title>

...所以标签助手可以从数据库中获取翻译并渲染:

&lt;title&gt;Login to Foobar&lt;/title&gt;

除了重命名原始标签之外,我根本看不到如何做任何事情,但我根本不想要任何标签。

这是我当前的代码:

public class TranslateTagHelper : TagHelper
{
    public string ResourceSet { get; set; } = "Global";

    public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
    {
        var content = await output.GetChildContentAsync();
        string originalContent = content.GetContent();

        output.Content.SetContent(@DbRes.T(originalContent, ResourceSet)); // Get translation from DB
    }
}

【问题讨论】:

    标签: asp.net-core-mvc asp.net-core-3.0 tag-helpers asp.net-core-tag-helpers


    【解决方案1】:

    好吧,原来我只需要这个:

    output.TagName = null;

    【讨论】:

      猜你喜欢
      • 2016-03-27
      • 2013-04-13
      • 2015-10-25
      • 1970-01-01
      • 2014-11-24
      • 1970-01-01
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多