Differences Between Razor and ASPX View Engine in MVC

View Engine renders the view into HTML form to the browser. If we talk about a MVC application in the .Net Framework, it supports the following 2 view engines:

  1. Razor View Engine
  2. Web Form/Aspx View Engine

Differences

  1. Entry with ASP.NET MVC
                       
    • Razor View Engine is an advanced view engine and introduced with MVC3. This is not a language but it is a markup syntax.
    • ASPX View Engine is the default view engine for the ASP.NET MVC that is included with ASP.NET MVC from the beginning.

      Razor and ASPX View
     
  2. Namespace

    • Razor View Engine supports System.Web.Razor.
    • ASPX View Engine supports System.Web.Mvc.WebFormViewEngine.
     
  3. Layout /MasterPage
                       
    • In Razor View Engine we use Layouts.
    • In ASPX View Engine we use masterPages.

      Layout
       
  4. PartialPage /WebUserControl

    • In Razor View Engine we use PartialPage.
    • In ASPX View Engine we use WebUserControls.

      PartialPage
     
  5. Extension

    • Razor View Engine has .cshtml (with C#) and .vbhtml (with VB) extension for views, Layout and Partial views.
    • ASPX View Engine has a similar extension as in a simple web application like .aspx for the views, .acsx for UserControls and .master for Master Pages.

      Extension
     
  6. Performance

    • Razor Engine is a little slow compared to Aspx Engine.
    • Aspx Engine is faster compared to Razor Engine.
     
  7. Syntax

    • ‘@’ symbol uses in Razor Engine to write the code. @Html.ActionLink("Login", "LoginView")
    • ‘<%:’ delimiters use as starting point and ‘ %>’ use as ending point. You can write the code between them in ASPX Engine.

    <%: Html.ActionLink("Login ", " LoginView ") %> 

    ActionLink

  8. Cross-Site Scripting Attacks

    • Razor Engine prevents Cross-Site Scripting Attacks, in other words it encodes the script or HTML tags like <,> before rendering to view.
    • ASPX Engine does not prevent Cross-Site Scripting Attacks, in other words any script saved in the database will be fired while rendering the page.


Similar Articles