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.
Leave A Comment