Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor: how to escape dot character next to a variable?

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?

like image 295
Cubius Avatar asked Apr 07 '14 19:04

Cubius


People also ask

How do you escape Razor syntax?

In Razor, `@` symbol is used to transition from HTML to C#. To escape an '@' symbol in razor markup, use two '@' symbols.

What does @: mean in Razor?

4. The @: sequence indicates that the line of content that follows should be treated as a content block: ("razor at colon" in Google).

How do you write if condition in Razor view?

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.

How do you write a multi statement code block in Razor?

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#.


1 Answers

Add parentheses:

<img src="/Content/img/icons/coins_@(size).png" /> 
like image 154
Cloud SME Avatar answered Sep 20 '22 23:09

Cloud SME