Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. public class WrapperTagHelper : TagHelper
  2. {
  3. public override void Process(TagHelperContext context, TagHelperOutput output)
  4. {
  5. output.TagName = "div";
  6. output.Attributes.SetAttribute(new TagHelperAttribute("class", "wrapper-tag-helper"));
  7.  
  8. string innerContent = renderInnerTagHelper(context);
  9.  
  10. string finalContent = $@"<p>Wrapper</p>
  11. {innerContent}";
  12.  
  13. output.Content.SetHtmlContent(finalContent);
  14. }
  15.  
  16. /*
  17. * This methods creates, processes and renders the InnerTagHelper
  18. */
  19. private string renderInnerTagHelper(TagHelperContext context)
  20. {
  21. InnerTagHelper innerTagHelper = new InnerTagHelper();
  22.  
  23. // Create a TagHelperOutput instance
  24. TagHelperOutput innerOutput = new TagHelperOutput(
  25. tagName: "",
  26. attributes: new TagHelperAttributeList(),
  27. getChildContentAsync: (useCachedResult, encoder) =>
  28. Task.Factory.StartNew<TagHelperContent>(
  29. () => new DefaultTagHelperContent()
  30. )
  31. );
  32.  
  33. // Process the InnerTagHelper instance
  34. innerTagHelper.Process(context, innerOutput);
  35.  
  36. // Render and return the tag helper attributes and content
  37. return $"<{innerOutput.TagName} {renderHtmlAttributes(innerOutput)}>{innerOutput.Content.GetContent()}</{innerOutput.TagName}>";
  38. }
  39. .
  40. .
  41. <code omitted here>
  42. .
  43. .
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement