I started learning ASP.NET MVC3.
So, while reading tutorials online and in books, I came across this term "view engine" quite frequently. I don't know what it is.
What does it actually do?
Why should it matter to me at all?
I started learning ASP.NET MVC3.
So, while reading tutorials online and in books, I came across this term "view engine" quite frequently. I don't know what it is.
What does it actually do?
Why should it matter to me at all?
View Engine renders the view into HTML form to the browser. If we talk about an MVC application in the .Net Framework, it supports the following 2 view engines:
1. Razor View Engine 2. Web Form/ASPX View Engine
Differences : 1. Razor View Engine uses Layouts but ASPX view engine uses Master pages.
2. Razor View Engine uses partial page but ASPX view engine uses Web User Control.
3. Razor view engine is not a language, It is Markup syntax.
4. @’ symbol uses in Razor Engine to write the code. @Html.ActionLink("Login", "LoginView") ‘<%:’ delimiters use as starting point and ‘ %>’ use as ending point. You can write the code between them in ASPX Engine.
5. Razor View Engine has .cshtml (with C#) and .vbhtml (with VB) extension for views, Layout and Partial views. ASPX View Engine has a similar extension as in a simple web application like .aspx for the views, .acsx for UserControls and .master for Master Pages.
In ASP.Net MVC, View engine is the one that works between your view and browser to provide valid HTML output to your browser by considering output provided by your view.There are many types of view engines.
1)ASPX
2)Razor
3)Spark
4)NHaml
5)NDJango
6)Hasic
7)Brail
Two View Engines:
ASPX
ASPX view engine, the server side script is wrapped between [% %] .ASPX is its extention.
Razor
Razor we use @. Switching between HTML and code is Possible. Razor View extention .CSHTML and .VBHTML
In MVC, View engine is the one that works between your View and browser to provide valid HTML output to your browser by compiling the code inside your View. There are many view engines available and some of them are following:
ASPX
Razor
Spark
NHaml
NDJango
Hasic
Brail
Bellevue
Sharp Tiles
String Template
Wing Beats
SharpDOM
Currently most developers prefer to use Razor view engine as it provides very convenient way of programming. All of these view engines may not support ASP.NET MVC.
For more details you can visit this article.
The view engine is what's responsible for rendering your view, and converting your code into glorious HTML. As such, they are directly responsible for HOW you need to write code in your views.
There's basically two ones you need to care about: ASPX and Razor. Razor is, in my opinion, much sleeker and easier to use, at the cost of only being supported in MVC3.
For example, a code block in ASPX might look like this:
Whereas the Razor equivalent will look like this:
I read a descriptive post at http://questionbox.in/view-engine-asp-net-mvc-razor-view-engine-asp-net-mvc-web-form-aspx-view-engine-asp-net-mvc/
View engine gives the ability to render the HTML from your view to the browser.
There are many view engines supported by ASP.NET MVC but the most widely used view engines are
Web form view engine / ASPX view engine:
.aspx, for Views just like Web Form pages. .ascx, for Partial Views & Editor Template just like User Controls. .master, for Layout and Master Pages just like Master Pages in Web Forms.
Razor View Engine:
Razor syntax is easy to understand and much clean than Web Form syntax. Razor uses @ symbol to make the code like as:
@Html.ActionLink(“Home”, “Index”)