Guest User

Untitled

a guest
Nov 18th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. using System;
  2. using Microsoft.AspNetCore.Mvc.ViewFeatures;
  3. using Microsoft.AspNetCore.Razor.TagHelpers;
  4.  
  5. namespace WebApplication.TagHelpers
  6. {
  7. /// <summary>
  8. /// <see cref="ITagHelper"/> implementation targeting <span> elements with an <c>asp-description-for</c> attribute.
  9. /// </summary>
  10. [HtmlTargetElement("span", Attributes = AttributeName)]
  11. public class DescriptionTagHelper : TagHelper
  12. {
  13. private const string AttributeName = "asp-description-for";
  14.  
  15. /// <summary>
  16. /// An expression to be evaluated against the current model.
  17. /// </summary>
  18. [HtmlAttributeName(AttributeName)]
  19. public ModelExpression For { get; set; }
  20.  
  21. public override void Process(TagHelperContext context, TagHelperOutput output)
  22. {
  23. if (context == null)
  24. {
  25. throw new ArgumentNullException(nameof(context));
  26. }
  27.  
  28. if (output == null)
  29. {
  30. throw new ArgumentNullException(nameof(output));
  31. }
  32.  
  33. if (!output.IsContentModified)
  34. {
  35. output.Content.SetContent(For.Metadata.Description);
  36. }
  37. }
  38. }
  39. }
Add Comment
Please, Sign In to add comment