Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor reseverd words

That the razor syntax is neat, there's little arguing about. But i can't seem to find it anywhere...
What are the razor reserved words?
@using
@inherits
@functions
@section
Do you know any other?

like image 517
marcelo-ferraz Avatar asked Dec 02 '10 18:12

marcelo-ferraz


People also ask

Is Cshtml a Razor?

cshtml files are razorpages or MVC views, they does not contain any C#-written client-side code. If you wan to do so, you must use JavaScript. However, a . razor file, also know as a Razor component, can have C# written in it and run on client's browser.

What are Razor expressions used for?

Razor Expression Encoding Razor provides expression encoding to avoid malicious code and security risks. In case, if user enters a malicious script as input, razor engine encode the script and render as HTML output.

Is Razor a language?

Razor is not a programming language. It's a server side markup language.


1 Answers

Here's a list of Razor reserved keywords (Note: This applies to cshtml, vbhtml follows VB's rules):

Razor-specific keywords

  • inherits
  • functions
  • section
  • helper
  • model (only in MVC projects)

You can escape these using @(inherits)

Language-specific Razor keywords

These are C# keywords that are understood by Razor

  • if
  • do
  • try
  • for
  • foreach
  • while
  • switch
  • lock
  • using
  • case
  • default

You can escape them using @(@lock) (first @ is used to escape the Razor parser and the second @ is used to escape the C# parser)

Reserved keywords

These are not reserved in RC but will be for RTM. Update: These will have no functionality for RTM. They are simply reserved for future use.

  • namespace
  • class
  • layout
like image 140
marcind Avatar answered Oct 14 '22 16:10

marcind