Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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>
- {innerContent}";
- output.Content.SetHtmlContent(finalContent);
- }
- /*
- * 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) =>
- Task.Factory.StartNew<TagHelperContent>(
- () => 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>
- .
- .
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement