The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConditionalElementTagHelper.cs 875B

1234567891011121314151617181920212223242526272829303132
  1. using Microsoft.AspNetCore.Mvc.Rendering;
  2. using Microsoft.AspNetCore.Mvc.ViewFeatures;
  3. using Microsoft.AspNetCore.Razor.TagHelpers;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. namespace Teknik.Utilities.TagHelpers
  8. {
  9. [HtmlTargetElement(Attributes = "conditional")]
  10. public class ConditionalElementTagHelper : TagHelper
  11. {
  12. [HtmlAttributeName("asp-condition")]
  13. public bool Condition { get; set; }
  14. [HtmlAttributeNotBound]
  15. [ViewContext]
  16. public ViewContext ViewContext { get; set; }
  17. public override void Process(TagHelperContext context, TagHelperOutput output)
  18. {
  19. base.Process(context, output);
  20. output.Attributes.RemoveAll("conditional");
  21. if (!Condition)
  22. {
  23. output.TagName = string.Empty;
  24. }
  25. }
  26. }
  27. }