1. What is Razor View Engine ?
View Engines are responsible for rendering the HTML from your views to the browser.
The Razor view engine is an advanced view engine from Microsoft, packaged with MVC 3. This is the default view engine in MVC 3 and MVC 4.
2. What are the Advantages of Razor View Engine ?
Syntax is compact and reduces typing – while at the same time improving the overall readability of markup and code.
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). As it's compiled to a class I can write a unit test and throw mocked instances of objects at it to see if the HTML is right.
IntelliSense and the Syntax are nice.
Compilation - Razor views can be compiled into a DLL. We can have a business object that knows how to display itself without having that code floating around as .ascx files in some part of the web project.
Razor doesn’t require a specific tool and enables you to be productive in any plain old text editor (notepad also works).
3. Comparison of Razor versus ASPX View Engine?
#
|
ASPX View Engine
|
Razor View Engine
|
1
|
File Extension is .cs (C#) and .vb
(VB.Net)
|
File Extension is cshtml (Razor with
C#) or vbhtml (Razor with VB).
|
2
|
Code blocks are enclosed in <%
%>.
|
Code blocks are enclosed in
@{.........}
|
3
|
Comment can be given as /*...*/ (C#)
|
Comment can be given as @*.........*@
|
4
|
Code-block should be exclusively closed.
|
Does not require you to explicitly
close the code-block, this view engine is parsed intelligently by the
run-time to determine what is a presentation element and what is a code
element.
|
5
|
Master Pages are used for consitent
look and feel.
|
Razor supports this concept using
“layout pages”
|
6
|
To Import the namespace in the View
-> using MVCTest.Controller;
|
For importing the namespace in the View
-> @using CustomNamespace
|
7
|
NameSpace system.Web.Mvc.WebFormViewEngine
|
NameSpace : System.Web.Razor
|
8
|
Performance : It will be bit faster when compare with Razor engine.
|
Performance : It is nominally a bit
slower when comparing with Aspx View Engine.
(Approximately 5% - 7%).
|
Razor kicks in at Execute result in asp.net MVC Page life cycle.
5. What is the file extension of Razor view engine ?
Web pages with Razor syntax have the special file extension cshtml (Razor with C#) or vbhtml (Razor with VB).
6. What Template does Razor view engine uses ?
Instead of MasterPages for the template, Razor uses Layouts.
7. How to add Namespaces in Razor view engine?
@using YourCustomNamespace
Eg : @using EmployeeNamespace
8. How Variables are declared in Razor View Engine ?
Variables are declared with the var keywords.
9. How inline expressions are declared in Razor View Engine?
All the inline expressions like variables and functions start with @.
Eg: <li @Html.Css("selected", Model.Mode == "map" )>STUFF</li>
10. What are the Different View engines which can be used in asp.net MVC ?
Asp.net supports different view engines apart from Razor and Asp.net View Engine.
Some of the other engines which MVC supports :
- Spark
- NHaml
- NDjango
- Hasic
- Brail
- Bellevue
- SharpTiles
- String Template
- Wing Beats
- SharpDOM
- XsltViewEngine (MvcContrib)
- NVelocityViewEngine (MvcContrib)
No comments:
Post a Comment