Razor ViewEngine: How do I escape the "@" symbol?

Aaronontheweb picture Aaronontheweb · Mar 13, 2011 · Viewed 47.4k times · Source

I'm trying to output some Twitter handles in ASP.NET MVC3 in conjunction with the Twitter @Anywhere API, and I haven't been able to figure out how to actually escape the "@" symbol in a Razor view.

Does anyone know what the syntax is for escaping the "@" character in Razor?

I've tried using <text></text> and that results in a JIT error.

Answer

JasCav picture JasCav · Mar 13, 2011

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

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