I am creating a sample ASP.NET MVC 3 site using Razor as view engine. The razor syntax starts with @
character e.g. @RenderBody()
. If I write @test on my cshtml page it gives me parse error
CS0103: The name 'test' does not exist in the current context
How do I escape '@' character?
In Razor, `@` symbol is used to transition from HTML to C#. To escape an '@' symbol in razor markup, use two '@' symbols.
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.
The Razor syntax consists of Razor markup, C#, and HTML. Files containing Razor generally have a . cshtml file extension.
The @ symbol is used in Razor initiate code, and tell the compiler where to start interpreting code, instead of just return the contents of the file as text. Using a single character for this separation, results in cleaner, compact code which is easier to read.
@@
should do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With