Overview of View Engines in ASP.NET MVC

By
 A View Engine is a MVC Subsystem which is responsible for rendering the view into HTML form to the Browser(Chrome,Internet Explorer,Firefox etc.).Initially,mvc 1 and mvc 2   template supports one view engine,that is called ASPX View Engine.  Microsoft introduced new View Engine  for MVC 3 template,that is called RAZOR View Engine. You can learn Namespaces in MVC template .There are two view engines for MVC template which was developed by Microsoft.
  1. ASPX
  2. RAZOR
At this time, ASP.NET MVC supports some open source view engines also. All view engines may not support all version of ASP.NET MVC template.
There are some other view engine also as give below:-
  • Spark
  • Nhaml
  • Hasic
  • NDjango
  • Bellevue
  • Brail etc.
How View Engine Works ?
Each view engine (open source,non open source) has using following components as given below:-
  • View Engine Class :-  This class implements the IViewEngine interface and responsible for locating view templates.You can see this class,when you will develop any  ASP.NET MVC application.
  • View Class :- This class implements the IViewEngine Interface and responsible for combing the template with data from the current context. This convert it to HTML Mark up as a output.
  • Template Parsing engine :- The View Engine parse the template and compiles the view executable code.
Note :-  You can use multiple view engine for your ASP.NET MVC application.
There are some concepts of View Engine in ASP.NET MVC template as give below:-
1.) ASPX :- 
  • This default view engine for MVC 1 and MVC 2 template. 
  • This view engine uses same syntax as asp.net web forms uses .
  • It uses file extension (.aspx,ascx,.master etc.) as asp.net web forms. 
  • It uses <% %> character for data binding purpose.
Example:-
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Index</title>
</head>
<body>
    <div>
   <b> <%= ViewData["title"] %></b>
    <br />
    The current Date and time in your System is: <%= ViewData["Date_Time"] %>
    </div>
</body>
</html>

2.) RAZOR :-  
  • Razor View Engine is an advanced view engine ,that was introduced Microsoft in MVC 3 template. 
  • Razor is a default view engine in MVC 3 and MVC 4 template.
  • Razor is a new markup syntax developed by Microsoft.
  •  Razor uses @ character to write the markup syntax.
  • Razor is more compact than other view engine.
  • Razor is a best view engine developed by Microsoft.
  • Razor is more compatible with unit testing.
  • Razor uses less codes to bind the data in mvc template.
  • Razor is very easy and much clean web form syntax. 
Example:-
@{
    ViewBag.Title = "View1";
}
<h1>Welcome to msdotnet.co.in</h1>
<h2>MY Frist View:- </h2>
<h3>
    Your @name, is good and the Date is: @Date_time
</h3>
3.) Spark :-  
This is an open source view engine for ASP.NET MVC template.

4.) NHaml :-  This is a markup language. It is used XHTML of any web document without using of inline code.It is an abstract description of XHTML.

5.) Bellevue :- In this view engine , data binding codes are separate from HTML markup.

6.) Brail :- This view engine is also used in ASP.NET MVC Template.

7.) NDjango :- This can also be used with ASP.NET MVC template.

8.) Hasic :- This view engine can  use in ASP.NET MVC template

0 comments:

Post a Comment

Powered by Blogger.