Skip to content

Instantly share code, notes, and snippets.

Last active February 20, 2017 22:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
public class WrapperTagHelper : TagHelper
public override void Process(TagHelperContext context, TagHelperOutput output)
output.TagName = "div";
output.Attributes.SetAttribute(new TagHelperAttribute("class", "wrapper-tag-helper"));
string innerContent = renderInnerTagHelper(context);
string finalContent = $@"<p>Wrapper</p>
* This methods creates, processes and renders the InnerTagHelper
private string renderInnerTagHelper(TagHelperContext context)
InnerTagHelper innerTagHelper = new InnerTagHelper();
// Create a TagHelperOutput instance
TagHelperOutput innerOutput = new TagHelperOutput(
tagName: "",
attributes: new TagHelperAttributeList(),
getChildContentAsync: (useCachedResult, encoder) =>
() => new DefaultTagHelperContent()
// Process the InnerTagHelper instance
innerTagHelper.Process(context, innerOutput);
// Render and return the tag helper attributes and content
return $"<{innerOutput.TagName} {renderHtmlAttributes(innerOutput)}>{innerOutput.Content.GetContent()}</{innerOutput.TagName}>";
<code omitted here>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment