Search code examples
c#asp.net-coreasp.net-core-mvc.net-core-2.0tag-helpers

Get HTML Content string from Taghelper


How do I get the HTML rendered from a Taghelper? Say I created a Taghelperfor a customized Checkbox. What would be the code to store the html in a variable?

checkboxTagHelper.ProcessAsync(checkboxContext, checkboxOutput);

In addition, I noticed renderHtmlAttributes does not work in .Net Core. However works in regular Mvc 4.6.3. Is this perhaps the correct method, and whats the equivalent in .Net Core?

http://blog.techdominator.com/article/rendering-a-tag-helper-inside-another-tag-helper.html

 return $"<{innerOutput.TagName} {renderHtmlAttributes(innerOutput)}>{innerOutput.Content.GetContent()}</{innerOutput.TagName}>";

Solution

  • Just researching, I believe the answer is this. Seems to be working on my end.

    return output.Content.GetContent();