In this post we have a tendency to area unit aiming to compare 2 major view Engines in ASP.NET MVC as well as ASPX view Engine and Razor view Engine. Let’s initial perceive What a reaud Engine is?
What is a view Engine in ASP.NET MVC?
“View Engine in ASP.NET MVC is employed to translate our views to HTML so render to response.”
Multiple view Engines area unit obtainable for MVC as well as ASPX, Razor, NHaml etc. unremarkably in ASP.NET MVC, a view Engine interprets read into HTML by:
Providing implementation of IViewEngine (as guide provider)
IView (as rendering template) and
A guide Engine for parsing and assembling view file into viable code.
We can even use multiple view Engines in parallel (if needed). For additional details regarding ViewEngine category, please follows here.
ASPX Vs Razor
Understanding Syntax distinction
Being software package developer, we have a tendency to area unit unremarkably involved regarding code syntax variations once exploitation either of those 2 view Engines. So, so as to urge higher understanding, please verify following code snip written exploitation each ASPX and Razor view Engine so as.
ASPX read Engine is additionally referred to as internet type view Engine and inherits it’s syntax as “<%= %>” or “<%: %>” for rendering server-side contents:
<%foreach (var student in Students) else %> <% } %>
Code snip for Razor view Engine serving same purpose:
@foreach (var student in Students) else }
It’s quite clear that Razor syntax is clean and easier as compared to ASPX syntax.ASP.NET MVC on-line take a look at
Detailed distinction Between ASPX view Engine and Razor view Engine
Now, following table describe the distinction in each view Engines in additional details.
ASPX view Engine
Razor view Engine
System.Web.Mvc.WebFormViewEngine is that the namespace for ASPX view Engine. Namespace for ASPX view Engine is System.Web.Razor.
File Extension for this read Engine is analogous to WebForm as:
.aspx, for Views a bit like internet type pages.
.ascx, for Partial Views & Editor guide a bit like User Controls.
.master, for Layout and Master Pages a bit like Master Pages in internet Forms.
As it’s new and advanced view Engine, it’s extensions area unit altogether totally different.
.cshtml (Razor C#), For all as well as Views, Partial Views, Editor guide and Layout Pages.
.vbhtml (Razor VB.NET), For all as well as Views, Partial Views, Editor guide and Layout Pages.