Created
March 14, 2023 12:05
-
-
Save bingzer/78852e67ec4320a0b9d9381b109230fa to your computer and use it in GitHub Desktop.
If block TagHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HtmlTargetElement("*", Attributes = "[asp-if]")] | |
public class IfTagHelper : TagHelper | |
{ | |
/// <summary> | |
/// Shows the element when this condition is true | |
/// </summary> | |
[HtmlAttributeName("asp-if")] | |
public bool IsTrue { get; set; } = true; | |
public override void Process(TagHelperContext context, TagHelperOutput output) | |
{ | |
if (!IsTrue) | |
{ | |
output.TagName = null; | |
output.Content.Clear(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment