Razor View Engine VS. Web Form/ASPX View Engine Razor

  1. Razor View Engine is an advanced view engine and introduced with MVC3 and it's the defualt view engine from MVC3. This is not a language but it is a markup syntax.

    ASPX View Engine is included with ASP.NET MVC from the beginning. This is the default view engine for the ASP.NET MVC 1 and MVC2.

  2. The namespace for Razor View Engine is System.Web.Razor in the System.Web.Razor assembly (in System.Web.Razor.dll) .

    The namespace for ASPX View Engine is System.Web.Mvc in the System.Web.Mvc assembly (in System.Web.Mvc.dll).

  3. In Razor View Engine we use Layouts, that serve the purpose of a master page in a web form application.

    In ASPX View Engine we use MasterPages like web form applications.

    MVC portal page

  4. In Razor View Engine we use PartialPage, that serve the purpose of UserControl in a web form application.

    In ASPX View Engine we use ViewUserControls for the purpose of UserControl in a web form application.

    MVC view user control

  5. Razor View Engine has .cshtml (for C#) and .vbhtml (for VB) extension for everything that renders (views, Layout and Partial views).

    page layout

    ASPX View Engine has a similar extension as web forms application like .aspx for the views, .acsx for UserControls and .master for Master Pages.

    master page

  6. Razor Engine prevents Cross-Site Scripting Attacks. It encodes the script or HTML tags before rendering to view. like <,> are encoded as &lt; @ &gt; respectively.

    ASPX Engine does not prevent Cross-Site Scripting Attacks. If there is some script in the content to be rendered, the script will be fired when rendering the page.

  7. Razor Engine supports Test Driven Development (TDD) since it is not dependent on the System.Web.UI.Page class.

    Web Form Engine doesn't support Test Driven Development (TDD) since it depends on the System.Web.UI.Page class that makes the testing complex.

  8. The Razor Engine doesn't support design mode in Visual Studio. You can drag a control from the tool box and drop it in your cshtml/.vbhtml page but you cannot see the look and feel of your page before your page renders on the browser.

    Source mode

    The Web Form engine supports design mode in Visual Studio. You can see the look and feel of your page (in design mode) without rendering it in the browser.

    About

  9. Razor has a new and advanced syntax that are compact, expressive and that reduces the number of keystrokes.

    Web Form Engine has the same syntax as that of ASP.NET Web Forms uses for .aspx pages.

  10. The Razor syntax is easy to learn and much cleaner than Web Form syntax.

    Web Form syntax is like ASP.NET Web Forms syntax, it makes a view messy.

  11. The "@" symbol is used in Razor Engine to write the code, for example @Html.ActionLink("Login", "LoginView").

    The "<%:" delimiter is the starting point and " %>" is the ending point. You can write the code between them in ASPX Engine, for example:
    <%: Html.ActionLink("Login ", " LoginView ") %>

  12. Razor View Engine does not require the code block to be closed, it parses and decides at runtime what the content element is and which is a code element.

    A web form view engine requires the code block to be closed properly otherwise it throws a runtime exception.

    Razor Syntax
    1. <table>  
    2. @foreach (var item in Model)
    3. {  
    4.    <tr>  
    5.          <td>@Html.DisplayFor(modelItem => item.Name)</td>  
    6.          <td>@Html.DisplayFor(modelItem => item.City)</td>  
    7.          <td>@Html.DisplayFor(modelItem => item.Country)</td>  
    8.          <td>@Html.DisplayFor(modelItem => item.ReviewsCount)</td>  
    9.    </tr>  
    10. }  
    11. </table>  
    Aspx Syntax
    1. <table>  
    2.    <% foreach (var item in Model)
    3.    { %>  
    4.          <tr>  
    5.                <td><%=Html.DisplayFor(modelItem => item.Name)%></td>  
    6.                <td><%=Html.DisplayFor(modelItem => item.City)%></td>  
    7.                <td><%=Html.DisplayFor(modelItem => item.Country)%></td>  
    8.                <td><%=Html.DisplayFor(modelItem => item.ReviewsCount)%></td>  
    9.          </tr>  
    10.    <% } %>  
    11. </table>  
  13. The Razor version has only three transition characters (@).

    Aspx version has 21 transition characters (the <% and %>)

  14. Razor uses "@* commented content goes here *@" for multi-line comments.

    The ASPX View Engine uses "<!--commented content goes here-->" for markup and "/* commented server-side code goes here */" for C# code.

  15. Razor view engine has better intellisense support than ASPX view engine.

  16. Razor Engine is a little slower than the Aspx Engine.


Similar Articles