What is View Engines

Introduction
 

Viewengine is the combination of HTML tags, Server Controls and a programming language and works inside the application for rendering view to the browser or to the user. So the main responsibility of View Engines is to create/render code into glorious HTML to the web browser, Every View Engines have its own set of syntax and controls.

There are number of view engines are available list give below and the choice of view engine is important, because the feature sets of view engines are quite different. Some support rendering to PDF files, for instance; Some can't be used outside a web context (this is true for the old ASP.NET view engine), while others can (e.g.Razor). 'Offline' rendering of views comes in handy when you want to create HTML emails the same way you build your views and those emails should be sent from a background worker rather than a web application. Now a days we can use multiple view engines in parallel in ASP.NET MVC, though it wouldn't recommend unless is requires.

Some common view engines

  1. ASPX

  2. Razor

  3. Spark

  4. NHaml

  5. NDJango

  6. Hasic

  7. Brail

Currently most developers prefer to use Razor(Microsoft) view engine for MVC framework. As it provides very convenient way of programming rather than ASPX. All of the above view engines may not support MVC.

Example

Lets take an syntax example of most common view engines: ASPX and Razor.

Razor, in my opinion, much sleeker and easier to use, Razor only being supported in MVC.
A code block in ASPX might look like this:

  1. <% foreach(var item in Model) { %>  
  2.   
  3. <tr>  
  4.   
  5.    <td><%: item.StudentName %></td>  
  6.   
  7. </tr>  
  8.   
  9. <% } %>  
Whereas the Razor equivalent will look like this:
  1. @foreach(var item in Model)
  2. {  
  3.   
  4.    <tr>  
  5.   
  6.          <td>@item.StudentName</td>  
  7.   
  8.    </tr>  
  9.   
  10. }  

Ebook Download
View all
Learn
View all