Razor reseverd words

不打扰是莪最后的温柔 提交于 2020-01-09 05:22:06

问题


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?


回答1:


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



回答2:


You've got them all. The only one I know of that's in the RC is @model but I don't see that in the list of RazorKeywords from the source so I'm not sure how that one is used or parsed.

If you check the source file "CSharpCodeParser.cs" under the WebPages/System.Web.Razor project you'll find a list of RazorKeywords.



来源:https://stackoverflow.com/questions/4338627/razor-reseverd-words

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!