- Razor View Engine is an advanced view engine and introduced
with MVC3 and it's the defualt view engine from MVC3. This is not a
language but it is a markup syntax.
ASPX View Engine is included with ASP.NET MVC from the beginning. This is the default view engine for the ASP.NET MVC 1 and MVC2. - The namespace for Razor View Engine is System.Web.Razor in the System.Web.Razor assembly (in System.Web.Razor.dll) .
The namespace for ASPX View Engine is System.Web.Mvc in the System.Web.Mvc assembly (in System.Web.Mvc.dll). - In Razor View Engine we use Layouts, that serve the purpose of a master page in a web form application.
In ASPX View Engine we use MasterPages like web form applications.
- In Razor View Engine we use PartialPage, that serve the purpose of UserControl in a web form application.
In ASPX View Engine we use ViewUserControls for the purpose of UserControl in a web form application.
- Razor
View Engine has .cshtml (for C#) and .vbhtml (for VB) extension for
everything that renders (views, Layout and Partial views).
ASPX View Engine has a similar extension as web forms application like .aspx for the views, .acsx for UserControls and .master for Master Pages.
- Razor
Engine prevents Cross-Site Scripting Attacks. It encodes the script or
HTML tags before rendering to view. like <,> are encoded as
< @ > respectively.
ASPX Engine does not prevent Cross-Site Scripting Attacks. If there is some script in the content to be rendered, the script will be fired when rendering the page. - Razor Engine supports Test Driven Development (TDD) since it is not dependent on the System.Web.UI.Page class.
Web Form Engine doesn't support Test Driven Development (TDD) since it depends on the System.Web.UI.Page class that makes the testing complex. - The
Razor Engine doesn't support design mode in Visual Studio. You can drag
a control from the tool box and drop it in your cshtml/.vbhtml page but
you cannot see the look and feel of your page before your page renders
on the browser.
The Web Form engine supports design mode in Visual Studio. You can see the look and feel of your page (in design mode) without rendering it in the browser.
- Razor has a new and advanced syntax that are compact, expressive and that reduces the number of keystrokes.
Web Form Engine has the same syntax as that of ASP.NET Web Forms uses for .aspx pages. - The Razor syntax is easy to learn and much cleaner than Web Form syntax.
Web Form syntax is like ASP.NET Web Forms syntax, it makes a view messy. - The "@" symbol is used in Razor Engine to write the code, for example @Html.ActionLink("Login", "LoginView").
The "<%:" delimiter is the starting point and " %>" is the ending point. You can write the code between them in ASPX Engine, for example:
<%: Html.ActionLink("Login ", " LoginView ") %> - Razor
View Engine does not require the code block to be closed, it parses and
decides at runtime what the content element is 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.
Razor Syntax- <table>
- @foreach (var item in Model)
- {
- <tr>
- <td>@Html.DisplayFor(modelItem => item.Name)</td>
- <td>@Html.DisplayFor(modelItem => item.City)</td>
- <td>@Html.DisplayFor(modelItem => item.Country)</td>
- <td>@Html.DisplayFor(modelItem => item.ReviewsCount)</td>
- </tr>
- }
- </table>
- <table>
- <% foreach (var item in Model)
- { %>
- <tr>
- <td><%=Html.DisplayFor(modelItem => item.Name)%></td>
- <td><%=Html.DisplayFor(modelItem => item.City)%></td>
- <td><%=Html.DisplayFor(modelItem => item.Country)%></td>
- <td><%=Html.DisplayFor(modelItem => item.ReviewsCount)%></td>
- </tr>
- <% } %>
- </table>
- The Razor version has only three transition characters (@).
Aspx version has 21 transition characters (the <% and %>) - Razor uses "@* commented content goes here *@" for multi-line comments.
The ASPX View Engine uses "<!--commented content goes here-->" for markup and "/* commented server-side code goes here */" for C# code. - Razor view engine has better intellisense support than ASPX view engine.
- Razor Engine is a little slower than the Aspx Engine.
Source Collected from CSharpcorner.com
http://www.c-sharpcorner.com/UploadFile/00a8b7/azor-view-engin-vs-web-formaspx-view-engine-razor/
No comments :
Post a Comment