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 | Webform view engine |
Razor view engine uses System.Web.Razor namespace | Webform view engine uses System.Web.Mvc. WebformViewEngine namespace |
Razor view engine uses @ syntax | Webform view engine uses < % %> |
Razor view engine prevents XSS attack | Webform view engine does not prevents XSS attack |
Razor view engine supports test driven approach | Webform view engine does not support test driven approach |
Razor view engine is slow as compared to webform view engine. | Webform view engine is quicker in performance as compared to razor view engine. |
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. |
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. |
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. |