[ACCEPTED]-Razor ViewEngine: How do I escape the "@" symbol?-twitter-anywhere

Accepted answer
Score: 161

You have to use @@ to escape the @ symbol.

One 5 important thing to notice is that you DO 4 NOT need to escape the @ symbol when it 3 exists within an email address. Razor should 2 be smart enough to figure that out on its 1 own.

Score: 31

If you are adding Twitter meta tags

and your 2 Twitter username is, say, foobar

it should look 1 like this

<meta name="twitter:site" content=@("@foobar")>
Score: 18

if you need to comment @ symbols in css 1 code and just @@ wont work, use this:

@("@@font-face"){ ... css ...}
Score: 4

I had yet another odd case: pass '@' + @Model.SomeProperty to a link 5 href.

The best solution for this case was 4 given IMO in this answer to a similar question. Both 3 @@ and @: didn't work while using the html code 2 &#64; would complicate things.

So, my code was 1 <a href="~/path/?query=@('@')@Model.SomePropery">

@Html.Raw('@')@Model.SomePropery would have worked as well.

Score: 0

If you are adding Schema.org JSON-LD Tags, @Matt's 1 answer worked for me:

  ....
  @("@context"): "https://schema.org",
  ....

More Related questions