Cubius
Cubius

Reputation: 1314

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?

Upvotes: 29

Views: 6242

Answers (2)

user2642885
user2642885

Reputation: 101

Just had to do something very similar earlier today. This should work for you:

<img src="/Content/img/icons/coins_@(size).png" />

Upvotes: 4

Andy T
Andy T

Reputation: 9881

Add parentheses:

<img src="/Content/img/icons/coins_@(size).png" />

Upvotes: 49

Related Questions