Razor View Engine vs Web Form View Engine

Note : Hi guys please visit new website for future posts http://www.dotnet-helpers.com. Thanks for support

 

What is View Engine in ASP.NET MVC and How It is used?

  • In Asp.net MVC, View engine holds the responsibility of rendering the view to the browser. MVC supports Razor Engine and Web Form by default
  • There are a lot of Third Party View engines available for use, We can go for them as well. Eg: Nhaml, Park, NDjango, SharpDOM etc.,

Lets see the difference between Razor and Web Form View engines.

Razor View Engine vs Web Form View Engine:

Release :

  • Razor Engine was introduced in MVC3
  • Web Form view engine is available since the MVC was introduced with its default View engine

File Extension :

  • Razor Engine has file extensions: 
    • .cshtml for C#
    • .cbhtml for VB, Partial Views, Editor Template and Layout Page.
  • Web Form Engine is set as default View engine in Visual Studio. It has file extensions:
    • .aspx for views
    • .ascx for partial view
    • .master for layouts

Base Class :

  • Namespace for Razor view engine is System.Web.Razor.
  • Namespace for Web Form view engine is System.Web.WebFormViewEngine.

Syntax :

  • In Razor View, we use the @ symbol succeeded by tag. It is not mandatory to explicitly close the code-block
    Eg : @Html.ActionLink(“Click”,”dotnet-Helpers.com”)
  • In Web Form view engine, we use <%: … %>
    Eg : <% :Html.ActionLink(“Click”,”dotnetHelpers”)%>

Comments :

  • Razor uses @* …. *@ for comments.
  • Web Form uses <!–…–> for comments.

Test Driven Development :

  • The Razor Engine supports TDD.
  • Web Form view engine does not support TDD because it depends on the System.Web.UI.Page class

Design Mode :

  • In Razor Engine, it does not support design mode in visual studio.(ie., Preview mode).
  • In Web Form Engine, it support design mode.