If I use an if statement to render a block of HTML in a Blazor WebAssembly app, does it actually get rendered and not displayed if the condition is false?
Something like this:
@if(isSectionVisible)
{
<div>Some HTML here</div>
}
Would this actually render the <div> and not display it if isSectionVisible is set to false or not render it at all?
Here's the actual scenario that I'm working on and the objective is to render only what's necessary and not just make it invisible to user. In my scenario, it's a big form with quite a few <InputText> controls user needs to fill out and be able to view the "terms and conditions" which comes from an external static URL if user chooses to. The whole thing is actually in a modal which is why I want to switch between the form and the iframe. I just don't want to open a modal on top of another.
<div>
@if(isFormVisible)
{
<EditForm>
... Omitted for brevity
</EditForm>
}
@if(isTermsAndConditionsVisible)
{
<iframe src="@termsAndConditionsUrl"></iframe>
}
</div>
@code {
bool isFormVisible = true;
bool isTermsAndConditionsVisible = false;
string termsAndConditionsUrl = "";
void TogglePanels(string panelName)
{
if(panelName == "terms-conditions")
{
termsAndConditionsUrl = "https://example.com";
isFormVisible = false;
isTermsAndConditionsVisible = true;
}
else
{
isFormVisible = true;
isTermsAndConditionsVisible = false;
termsAndConditionsUrl = "";
}
}
}