Differences between Razor and ASPX View Engine in MVC?

Category: C SharpDifferences between Razor and ASPX View Engine in MVC?
Editor">Editor Staff asked 2 years ago

Differences between Razor and ASPX View Engine in MVC?

1 Answers
Editor">Editor Staff answered 2 years ago

Razor View Engine VS ASPX View Engine
 

Razor View Engine
ASPX View Engine (Web form view engine)

The namespace used by the Razor View Engine is System.Web.Razor
The namespace used by the ASPX View Engine is System.Web.Mvc.WebFormViewEngine

The file extensions used by the Razor View Engine are different from a web form view engine. It uses cshtml with C# and vbhtml with vb for views, partial view, templates and layout pages.
The file extensions used by the Web Form View Engines are like ASP.Net web forms. It uses the ASPX extension to view the aspc extension for partial views or User Controls or templates and master extensions for layout/master pages.

The Razor View Engine is an advanced view engine that was introduced with MVC 3.0. This is not a new language but it is markup.
A web form view engine is the default view engine and available from the beginning of MVC

Razor has a syntax that is very compact and helps us to reduce typing.
The web form view engine has syntax that is the same as an ASP.Net forms application.

The Razor View Engine uses @ to render server-side content.
The ASPX/web form view engine uses “<%= %>” or “<%: %>” to render server-side content.

By default all text from an @ expression is HTML encoded.
There is a different syntax (“<%: %>”) to make text HTML encoded.

Razor does not require the code block to be closed, the Razor View Engine parses itself and it is able to decide at runtime which is a content element 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.

The Razor View Engine prevents Cross-Site Scripting (XSS) attacks by encoding the script or HTML tags before rendering to the view.
A web form View engine does not prevent Cross-Site Scripting (XSS) attacks.

The Razor Engine supports Test Driven Development (TDD).
Web Form view engine does not support Test Driven Development (TDD) because it depends on the System.Web.UI.Page class to make the testing complex.

Razor uses “@* … *@” for multiline comments.
The ASPX View Engine uses “<!–…–>” for markup and “/* … */” for C# code.

There are only three transition characters with the Razor View Engine.
There are only three transition characters with the Razor View Engine.

 
The Razor View Engine is a bit slower than the ASPX View Engine.
 
Conclusion
 
Razor provides a new view engine with a streamlined code for focused templating. Razor’s syntax is very compact and improves the readability of the markup and code. By default, MVC supports ASPX (web forms) and Razor View Engine. MVC also supports third-party view engines like Spark, Nhaml, NDjango, SharpDOM and so on. ASP.NET MVC is open source.