Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor Razor return statement in HTML

Tags:

razor

blazor

I recently inherited a Blazor project and come across many .razor files that are like:

<h1>Some header text></h1>
@if(someCondition) {
<div> lots of html and what not here taking up many lines</div>
} else {
<div> more html taking up many lines</div>
}

What I'm wondering is if there is a syntax that will allow me to eliminate the "else" statements that are hiding in the weeds, by having a return statement in my "if" condition. Meaning:

<h1>Some header text></h1>
@if(someCondition) {
<div> lots of html and what not here taking up many lines</div>
return //JUST BAIL HERE INSTEAD OF HAVING TO START AN ELSE BLOCK LIKE I DO ELSEWHERE IN LIFE
}

<div> more html taking up many lines</div>
like image 877
Ray Avatar asked Oct 18 '25 03:10

Ray


1 Answers

Yes. You can use return; this ends the RenderFragment no other content is drawn.

blazor repl

like image 61
Brian Parker Avatar answered Oct 22 '25 06:10

Brian Parker