Skip to content

Instantly share code, notes, and snippets.

@bingzer
Created March 14, 2023 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bingzer/78852e67ec4320a0b9d9381b109230fa to your computer and use it in GitHub Desktop.
Save bingzer/78852e67ec4320a0b9d9381b109230fa to your computer and use it in GitHub Desktop.
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