ShowIfTagHelper Class

A TagHelper that conditionally renders elements based on a boolean expression.

public sealed class ShowIfTagHelper : TagHelper

Example

@model FormModel

@* Show content only if user is authenticated *@
<div show-if="@(User.Identity?.IsAuthenticated == true)">
    Welcome back, @User.Identity?.Name!
</div>

@* Show error message conditionally *@
<div class="alert alert-danger" show-if="@Model.HasErrors">
    Please correct the errors below.
</div>
Inheritance
TagHelper ShowIfTagHelper

Constructors

NameDescription
ShowIfTagHelper()

ShowIfTagHelper()

public ShowIfTagHelper()

No documentation is available.

Properties

NameDescription
ValueGets or sets the condition that determines whether the element should be rendered.

Gets or sets the condition that determines whether the element should be rendered.

public bool Value { get; set; }

Property value

bool When true, the element is rendered; when false, it is suppressed.

Methods

NameDescription
Process(TagHelperContext, TagHelperOutput)Processes the tag helper by either rendering or suppressing the element based on the condition.

Process(TagHelperContext, TagHelperOutput)

ShowIfTagHelper.cs

Processes the tag helper by either rendering or suppressing the element based on the condition.

public override void Process(TagHelperContext context, TagHelperOutput output)

Parameters

context TagHelperContext
Contains information about the current tag.
output TagHelperOutput
A stateful HTML element used to generate an HTML tag.