如果我有这样的标签:
<foo>Some content</foo>
如何获取 TagHelper 中的内容?
我在 TagHelper
或 TagHelperContext
上看不到任何内容。
我正在尝试解析标签的内容。
最佳答案
解决方案有点不直观,通过 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"
}
关于c# - 在 TagHelper 中获取标签内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48770880/