Skip to content

Instantly share code, notes, and snippets.

@scottsauber
Last active January 4, 2017 02:37
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 scottsauber/296b2a489620bcaa81e1855a2348b8fe to your computer and use it in GitHub Desktop.
Save scottsauber/296b2a489620bcaa81e1855a2348b8fe to your computer and use it in GitHub Desktop.
// Add more target elements here on a new line if you want to target more than just div. Example: [HtmlTargetElement("a")] to hide/show links
[HtmlTargetElement("div")]
public class VisibilityTagHelper : TagHelper
{
// default to true otherwise all existing target elements will not be shown, because bool's default to false
public bool IsVisible { get; set; } = true;
// You only need one of these Process methods, but just showing the sync and async versions
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (!IsVisible)
output.SuppressOutput();
base.Process(context, output);
}
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
if (!IsVisible)
output.SuppressOutput();
return base.ProcessAsync(context, output);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment