Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Blazor – HTML tag inside of c# bound bool switch

I want to add a icon into a button context depending on a bool.

How to implement a HTML tag into a c# bound bool switch?

<button type="button"> 
   @(SwitchBool? "Save" : @"<i class='\u0022'fa fa-pen'\u0022'></i>")
</button>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can do it like this:

<button type="button" @onclick="() => SwitchBool = !SwitchBool"> 
   @if(SwitchBool)
   {
       <text>Save</text>
   }
   else
   {
       <i class="fa fa-pen"></i>
   }
</button>

@code {
    private bool SwitchBool;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading