Skip to content

Instantly share code, notes, and snippets.

@bingzer
Created March 14, 2023 12:05
Embed
What would you like to do?
If block TagHelper
[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