<html>
<body style="font-family:Arial; font-size:medium; color:darkblue">
<h2>Vew Engin Demo</h2>
<!-- Single statement blocks -->
@{ var RollNo = 7; }
@{ var StudentName = "Raj Parihar";
<!-- Inline expressions -->
<p>The student RollNo is:= @RollNo </p>
<p>Name := @StudentName</p>
<!-- Multi-statement block -->
@{
var greeting = "Welcome to our site! Mr. " + @StudentName;
var Department = "Your department is IT";
var myMessage = greeting + " " + Department;
}
<p>The greeting is: @myMessage</p>
@if (Model != null)
{
foreach (var item in Model)
{
<ul>
<li>
@Html.DisplayFor(modelItem => item.Name)
</li>
<li>
@Html.DisplayFor(modelItem => item.Address)
</li>
<li>
@Html.DisplayFor(modelItem => item.City)
<br />
</li>
</ul>
}
}
<%
string strVariable = "Hello World !!";
bool boolVar = true;
string[] arrVar = new string[] { "A", "B", "C"};
%>
<ul>
<%foreach (var item in ListItem)
{ %>
<li><%=item%></li>
<%}
%>
</ul>
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
<p>
To learn more MVC, click the following link:
<%= Html.ActionLink("About this Website", "Home" ) %>
<br/><br/>
<label for=”FirstName”>First Name:</label>
<%= Html.TextBox("FirstName") %>
<%= Html.ValidationMessage("FirstName", "*") %>
</p>
</div>
</body>
</html>
ASPX View Engine | RAZOR View Engine |
---|---|
System.Web.Mvc.WebFormViewEngine is the namespace for ASPX View Engine. | System.Web.Razor is the namespace for ASPX view Engine. |
Default view engine from the beginning (MVC 1.0) | Introduced in ASP.NET MVC v3 |
.aspx is file extension for web page and .ascx is for user controls | .cshtml (with C#) and .vbhtml (with VB) extension for views, Layout and Partial views |
No support for TDD (Test Driven Development). | Supports TDD (Test Driven Development). |
ASPX View Engine is comparatively fast. | It is slow as compared to ASPX View Engine. |
No support for Cross-Site Scripting attacks. | Supports for Cross-Site Scripting attacks. |