Hi i just downloaded MVC 3 and found an new view engine called "RAZOR". How is it useful?
嗨,我刚刚下载了MVC 3,发现了一个叫做“RAZOR”的新视图引擎。是如何有用吗?
What benefits does it provide?
它能带来什么好处?
How is different from ASPX pages?
与ASPX页面有何不同?
Where should one use RAZOR view engine?
在什么地方应该使用剃刀视图引擎?
3 个解决方案
#1
18
Scott Gu covered most of your questions in his Razor introductory blog post:
Scott Gu在他的剃刀入门博客中回答了你的大部分问题:
The new view-engine option we’ve been working on is optimized around HTML generation using a code-focused templating approach
我们一直在研究的新的视图引擎选项是使用代码集中的模板方法围绕HTML生成进行优化的
...
…
Compact, Expressive, and Fluid: Razor minimizes the number of characters and keystrokes required in a file, and enables a fast, fluid coding workflow. Unlike most template syntaxes, you do not need to interrupt your coding to explicitly denote server blocks within your HTML. The parser is smart enough to infer this from your code. This enables a really compact and expressive syntax which is clean, fast and fun to type.
紧凑、富有表现力和流畅性:Razor最小化文件中所需的字符和击键数量,并支持快速、流畅的编码工作流。与大多数模板语法不同,您不需要中断编码以显式地表示HTML中的服务器块。解析器足够聪明,可以从代码中推断出这一点。这使得语法非常紧凑,表达能力强,打字简洁、快速、有趣。
Easy to Learn: Razor is easy to learn and enables you to quickly be productive with a minimum of concepts. You use all your existing language and HTML skills.
容易学:Razor很容易学,你可以用最少的概念快速提高效率。您使用所有现有的语言和HTML技能。
Is not a new language: We consciously chose not to create a new imperative language with Razor. Instead we wanted to enable developers to use their existing C#/VB (or other) language skills with Razor, and deliver a template markup syntax that enables an awesome HTML construction workflow with your language of choice.
不是一门新的语言:我们有意识地选择不去创造一种新的命令式语言。相反,我们希望让开发人员能够使用Razor使用他们现有的c# /VB(或其他)语言技能,并提供一个模板标记语法,使您可以使用自己选择的语言创建一个很棒的HTML构建工作流。
Works with any Text Editor: Razor doesn’t require a specific tool and enables you to be productive in any plain old text editor (notepad works great).
与任何文本编辑器一起工作:Razor不需要一个特定的工具,可以让你在任何普通的旧文本编辑器中高效工作(记事本很有用)。
Has great Intellisense: While Razor has been designed to not require a specific tool or code editor, it will have awesome statement completion support within Visual Studio. We’ll be updating Visual Studio 2010 and Visual Web Developer 2010 to have full editor intellisense for it.
拥有强大的智能感知能力:Razor被设计成不需要特定的工具或代码编辑器,但在Visual Studio中,它将提供出色的语句完成支持。我们将更新Visual Studio 2010和Visual Web Developer 2010,使其具有完整的编辑器智能感知。
- Unit Testable: The new view engine implementation will support the ability to unit test views (without requiring a controller or web-server, and can be hosted in any unit test project – no special app-domain required).
- 单元可测试性:新的视图引擎实现将支持单元测试视图的能力(不需要控制器或web服务器,可以托管在任何单元测试项目中——不需要特殊的应用程序域)。
#2
8
Difference Between Razor View Engine and ASPX View Engine in MVC
Razor视图引擎和ASPX视图引擎在MVC中的区别
http://royalarun.blogspot.in/2013/12/difference-between-razor-view-engine.html
http://royalarun.blogspot.in/2013/12/difference-between-razor-view-engine.html
ASPX View Engine is the default view engine for the Asp.net MVC that is included with Asp.net MVC from the beginning.
Razor Engine is an advanced view engine that was introduced with MVC3. This is not a new language but it is a new markup syntax.
ASPX视图引擎是Asp.net MVC的默认视图引擎,从一开始就包含在Asp.net MVC中。Razor引擎是MVC3引入的一种高级视图引擎。这不是一种新的语言,而是一种新的标记语法。
ASPX View Engine doesn't support TDD (Test Driven Development)
Razor Engine supports TDD (Test Driven Development)
ASPX视图引擎不支持TDD(测试驱动开发)剃刀引擎支持TDD(测试驱动开发)
ASPX View Engine support design mode in visual studio means you can see your page look and feel without running the application.
Razor Engine, doesn't support design mode in visual studio means you cann't see your design page look and feel.
在visual studio中,ASPX视图引擎支持设计模式意味着您可以在不运行应用程序的情况下看到页面的外观和感觉。剃刀引擎,不支持设计模式在visual studio意味着你看不到你的设计页面的外观和感觉。
ASPX View Engine is faster than Razor Engine.
Razor Engine is little bit slow as compared to Webform Engine.
ASPX视图引擎比剃须刀引擎快。剃须刀引擎比Webform引擎慢一点。
Syntax Webform uses <% and %> for example
例如,语法Webform使用<%和%>
< %: Html.ActionLink("SignUp", "SignUp") % >
Razor uses @ symbol for example
Razor使用@符号。
@Html.ActionLink("SignUp", "SignUp")
ASPX View Engine does not prevent XSS attacks means any script saved in the database will be fired while rendering the page.
Razor Engine prevents XSS attacks(Cross-Site Scripting Attacks) means it encodes the script or html tags like <,> before rendering to view.
ASPX视图引擎不能防止XSS攻击,这意味着在呈现页面时将触发保存在数据库中的任何脚本。Razor引擎可以防止XSS攻击(跨站点脚本攻击),这意味着它在呈现视图之前会对脚本或html标签进行编码,比如<,>。
#3
3
Although a bit out of date qua syntax: ScottGu explains most of it.
虽然有点过时的qua语法:ScottGu解释了大部分。
Quick Syntax reference can be found on Haacked blog.
可以在Haacked blog上找到快速语法参考。
#1
18
Scott Gu covered most of your questions in his Razor introductory blog post:
Scott Gu在他的剃刀入门博客中回答了你的大部分问题:
The new view-engine option we’ve been working on is optimized around HTML generation using a code-focused templating approach
我们一直在研究的新的视图引擎选项是使用代码集中的模板方法围绕HTML生成进行优化的
...
…
Compact, Expressive, and Fluid: Razor minimizes the number of characters and keystrokes required in a file, and enables a fast, fluid coding workflow. Unlike most template syntaxes, you do not need to interrupt your coding to explicitly denote server blocks within your HTML. The parser is smart enough to infer this from your code. This enables a really compact and expressive syntax which is clean, fast and fun to type.
紧凑、富有表现力和流畅性:Razor最小化文件中所需的字符和击键数量,并支持快速、流畅的编码工作流。与大多数模板语法不同,您不需要中断编码以显式地表示HTML中的服务器块。解析器足够聪明,可以从代码中推断出这一点。这使得语法非常紧凑,表达能力强,打字简洁、快速、有趣。
Easy to Learn: Razor is easy to learn and enables you to quickly be productive with a minimum of concepts. You use all your existing language and HTML skills.
容易学:Razor很容易学,你可以用最少的概念快速提高效率。您使用所有现有的语言和HTML技能。
Is not a new language: We consciously chose not to create a new imperative language with Razor. Instead we wanted to enable developers to use their existing C#/VB (or other) language skills with Razor, and deliver a template markup syntax that enables an awesome HTML construction workflow with your language of choice.
不是一门新的语言:我们有意识地选择不去创造一种新的命令式语言。相反,我们希望让开发人员能够使用Razor使用他们现有的c# /VB(或其他)语言技能,并提供一个模板标记语法,使您可以使用自己选择的语言创建一个很棒的HTML构建工作流。
Works with any Text Editor: Razor doesn’t require a specific tool and enables you to be productive in any plain old text editor (notepad works great).
与任何文本编辑器一起工作:Razor不需要一个特定的工具,可以让你在任何普通的旧文本编辑器中高效工作(记事本很有用)。
Has great Intellisense: While Razor has been designed to not require a specific tool or code editor, it will have awesome statement completion support within Visual Studio. We’ll be updating Visual Studio 2010 and Visual Web Developer 2010 to have full editor intellisense for it.
拥有强大的智能感知能力:Razor被设计成不需要特定的工具或代码编辑器,但在Visual Studio中,它将提供出色的语句完成支持。我们将更新Visual Studio 2010和Visual Web Developer 2010,使其具有完整的编辑器智能感知。
- Unit Testable: The new view engine implementation will support the ability to unit test views (without requiring a controller or web-server, and can be hosted in any unit test project – no special app-domain required).
- 单元可测试性:新的视图引擎实现将支持单元测试视图的能力(不需要控制器或web服务器,可以托管在任何单元测试项目中——不需要特殊的应用程序域)。
#2
8
Difference Between Razor View Engine and ASPX View Engine in MVC
Razor视图引擎和ASPX视图引擎在MVC中的区别
http://royalarun.blogspot.in/2013/12/difference-between-razor-view-engine.html
http://royalarun.blogspot.in/2013/12/difference-between-razor-view-engine.html
ASPX View Engine is the default view engine for the Asp.net MVC that is included with Asp.net MVC from the beginning.
Razor Engine is an advanced view engine that was introduced with MVC3. This is not a new language but it is a new markup syntax.
ASPX视图引擎是Asp.net MVC的默认视图引擎,从一开始就包含在Asp.net MVC中。Razor引擎是MVC3引入的一种高级视图引擎。这不是一种新的语言,而是一种新的标记语法。
ASPX View Engine doesn't support TDD (Test Driven Development)
Razor Engine supports TDD (Test Driven Development)
ASPX视图引擎不支持TDD(测试驱动开发)剃刀引擎支持TDD(测试驱动开发)
ASPX View Engine support design mode in visual studio means you can see your page look and feel without running the application.
Razor Engine, doesn't support design mode in visual studio means you cann't see your design page look and feel.
在visual studio中,ASPX视图引擎支持设计模式意味着您可以在不运行应用程序的情况下看到页面的外观和感觉。剃刀引擎,不支持设计模式在visual studio意味着你看不到你的设计页面的外观和感觉。
ASPX View Engine is faster than Razor Engine.
Razor Engine is little bit slow as compared to Webform Engine.
ASPX视图引擎比剃须刀引擎快。剃须刀引擎比Webform引擎慢一点。
Syntax Webform uses <% and %> for example
例如,语法Webform使用<%和%>
< %: Html.ActionLink("SignUp", "SignUp") % >
Razor uses @ symbol for example
Razor使用@符号。
@Html.ActionLink("SignUp", "SignUp")
ASPX View Engine does not prevent XSS attacks means any script saved in the database will be fired while rendering the page.
Razor Engine prevents XSS attacks(Cross-Site Scripting Attacks) means it encodes the script or html tags like <,> before rendering to view.
ASPX视图引擎不能防止XSS攻击,这意味着在呈现页面时将触发保存在数据库中的任何脚本。Razor引擎可以防止XSS攻击(跨站点脚本攻击),这意味着它在呈现视图之前会对脚本或html标签进行编码,比如<,>。
#3
3
Although a bit out of date qua syntax: ScottGu explains most of it.
虽然有点过时的qua语法:ScottGu解释了大部分。
Quick Syntax reference can be found on Haacked blog.
可以在Haacked blog上找到快速语法参考。