在 TagHelper 中获取标签内容

Get tag content in TagHelper

如果我有这样的标签:

<foo>Some content</foo>

如何获取 TagHelper 中的内容?

我在 TagHelperTagHelperContext 上看不到任何内容。

我正在尝试解析标签的内容。

解决方案有点不直观,您通过 TagHelperOutput.GetChildContentAsync() 方法从 TagHelperOutput 中获取内容。

如果我们有这样的标签:

<my-tag>Some content</my-tag>

然后

public override void Process(TagHelperContext context, TagHelperOutput output)
{
    var childContext = output.GetChildContentAsync().Result;
    var content = childContext.GetContent();
    // content == "Some content"
}