Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

asp.net mvc 3 - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...