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 Parameter reference with at symbol but within a text

How to make @Text act as Parameter but within a text?

For example, here

<div class="alert alert-@AlertClassType">some@Text</div>

some@Text is treated as a plain text,
but when string Text="thing" I’d expect ‘something’ in the result. I am clear, am I?

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

If I’d do

<div class="alert alert-@AlertClassType">some @Text</div>

it will "work" but that extra space before @ will also appear in the rendered content,
how to avoid that?

>Solution :

@ symbol denotes the start of C# code block, if used with existing markup then you will need to specify that the @ you’re using is a code block explicitly by using ().

<div class="alert">some@(Text)</div>

Another tip,
If you want to specify that the @() you’re using is not a code block then you can use the @@ escape sequence.

<div class="alert">some@@(Text)</div>

Snippet

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