November 10, 2013

The ASP.NET MVC View Engine

View Engine in MVC 4

In general, view engine is combination of markup language and programming language. View engine is responsible to create HTML from the View. This is a two step process. ASP.Net supports multiple types of view engine such as: Razor, ASPX, Spark, Brail etc. Also, MVC provides flexibility for a custom view engine. Here, we will discuss about the view engine majorly in use.

ASPX: This is like a traditional ASPX page embedded with the markup language which requires defining of opening and closing tag as syntax. Extension for ASPX is .aspx

Syntax: <%: %>

Example: <%: Html.Label("Hello world!") %>

Razor:  This is a powerful and more flexible view engine as compared to ASPX. The line of code starts with @ symbol and does not require closing tag. Extension for Razor is depends on programming language you have selected. For C#, its .cshtml, for VB.Net its .vbhtml and so on.

Syntax: @

Example: @Html.Label("Hello world!")

In both above cases, output will be: Hello world!

Your comments, likes, dislikes are very important to make it better.
All code samples are available on requests.