Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape @ character in razor view engine

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?

like image 340
ajay_whiz Avatar asked Sep 02 '10 10:09

ajay_whiz


People also ask

How do you escape the Razor page?

In Razor, `@` symbol is used to transition from HTML to C#. To escape an '@' symbol in razor markup, use two '@' symbols.

How do you use the symbol on Razor page?

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.

Which of the following represents Razor syntax?

The Razor syntax consists of Razor markup, C#, and HTML. Files containing Razor generally have a . cshtml file extension.

What is @model in Razor?

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.


1 Answers

@@ should do it.

like image 62
Tobiasopdenbrouw Avatar answered Oct 07 '22 13:10

Tobiasopdenbrouw