如何从ASP.NET核心标记助手

时间:2016-11-21 20:20:30

标签: asp.net-core asp.net-core-mvc

我看到很多使用ASP.NET核心标记助手的示例使用ProcessAsync来获取HTML元素的InnerText。例如,以下按预期工作:

    public override async Task ProcessAsync(TagHelperContext context,
                              TagHelperOutput output)
    {
        var childContent = await output.GetChildContentAsync();
        var innerHtml = childContent.GetContent();
        output.Content.SetHtmlContent("---" + innerHtml + "---"); 
    }

但是,我希望同步获得它,以下不会。如何通过Process(sync)获取innertext?

    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
        var innerHtml = output.Content.GetContent();
        output.Content.SetHtmlContent("---" + innerHtml + "---");
    }

1 个答案:

答案 0 :(得分:4)

为什么呢?它对你的情况有什么不同?你认为你在做什么需要同步访问?

如果你认为你确实需要它,那么

var innerHtml = output.GetChildContentAsync().Result.GetContent();
相关问题