I have a size
variable which I need to insert in HTML, like this:
<img src="/Content/img/icons/[email protected]" />
to get something like this:
<img src="/Content/img/icons/coins_16.png" />
But ASP.NET thinks that png
is a method of size
. Is there a way to escape the dot coming after the variable?
In Razor, `@` symbol is used to transition from HTML to C#. To escape an '@' symbol in razor markup, use two '@' symbols.
4. The @: sequence indicates that the line of content that follows should be treated as a content block: ("razor at colon" in Google).
The If Condition The if statement returns true or false, based on your test: The if statement starts a code block. The condition is written inside parenthesis. The code inside the braces is executed if the test is true.
Multi-statement Code blockYou can write multiple lines of server-side code enclosed in braces @{ ... } . Each line must ends with a semicolon the same as C#.
Add parentheses:
<img src="/Content/img/icons/coins_@(size).png" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With