Thoughts on Software

Escaping the @ character in ASP.Net MVC Razor Views

with 6 comments

The Razor view engine uses the ‘@’ character to identify code directives within the view. So, what do you do if you need to use an @ character within a Razor code statement block? You simply escape it with @@: @@ is the escape character for @ in Razor views.

Razor, like most things MVC, is actually pretty smart however and tries to work out from context when an ‘@’ is just an ‘@’ and where it marks C# (or VB.Net) code.

One of the main uses for this is to identify email addresses within a Razor view – it should not be necessary to escape the @ character in an email address.

Written by andrewlocatelliwoodcock

May 10, 2011 at 20:14

Posted in ASP.Net MVC, Razor

Tagged with , , , ,

6 Responses

Subscribe to comments with RSS.

  1. Great job

    Tamar Piwetz

    May 28, 2011 at 16:35

  2. I like your article

    Shawnee Sylney

    May 28, 2011 at 20:48

  3. Interesting Info, Never knew about it.

    Daniel Cragi

    November 19, 2013 at 14:45

  4. Interesting info. Never knew about it. Thanks for sharing 🙂


    November 19, 2013 at 14:46

  5. Good to know that you don’t have to escape the @ for an email address.

    Ken H

    January 28, 2014 at 05:46

  6. Never heard of this tip. Thanks for sharing it.


    March 7, 2014 at 02:52

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: