How to put a @ inside {} in MVC

7

When doing a page in MVC5 with Razor, I put the following code

   {--conteúdo da @ RenderBody() etc, etc }

Generated an error because @ is inside braces

ERROR:

Server Error in '/' Application.

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: A space or line break was encountered after the "@" character.  Only valid identifiers, keywords, comments, "(" and "{" are valid at the start of a code block and they must occur immediately following "@" with no space in between.


Source Error: 


Line 74:         </aside>
Line 75:         <!-- PAINEL PRINCIPAL -->
Line 76: {--conteúdo da @ RenderBody()
Line 77:         <div id="main">     
Line 78:             <div id="ribbon">

Source File: /Views/Home/padroes_layout.cshtml    Line: 76 

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34009

How to put the at sign inside? and if I want to write @RenderBody () has no way?

    
asked by anonymous 30.04.2014 / 20:41

2 answers

6

Alternative 1

Just type the duplicate symbol: @@ .

This will be turning into just a @ into the output.

In short, correlating with your question, to write "@RenderBody()" to the output of a view razor, just write it:

@@RenderBody()

Alternative 2

Another option, which may be useful in other cases, is to make the razor render an object, which can be anything, including the string "@RenderBody()" :

@("@RenderBody()")
    
30.04.2014 / 20:45
2

Use of (@) in Razor

"The special character @ starts an expression, a block with a single statement or several, for example, we can insert a Razor code directly into the HTML markup, using the @ character to start a condition expression or display the content of a variable. " (Alexandre Tadashi Sato, Introduction to ASP.NET Razor. Available

30.04.2014 / 22:39