Q:

How do I conditionally add Blazor components’ template?

0

This code will help you to understand how to conditionally add Blazor components’ template.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

The if the statement is used to display a component or fragment conditionally. If the condition evaluates to true, the component will be loaded to the view.

Whenever the properties used in the if statement change

<button class="btn" @onclick="ButtonClicked">Show</button>
 
@if (ShowComponent)
{
    <FetchData></FetchData>
}
 
@code{
    public bool ShowComponent { get; set; }
 
    public void ButtonClicked(MouseEventArgs e)
    {
        ShowComponent = true;
    }
}

, the condition evaluates to either true or false and adds or removes the component to the page.

Refer to the following code sample.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now