The if 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 changes, the condition evaluates to either true or false and adds or removes the component to the page.
Refer to the following code sample.
<button class="btn" @onclick="ButtonClicked">Show</button>
@if (ShowComponent)
{
<FetchData></FetchData>
}
@code{
public bool ShowComponent { get; set; }
public void ButtonClicked(MouseEventArgs e)
{
ShowComponent = true;
}
}
Share with