1. Introducing Razor A new view engine for ASP.NET Shiju Varghese Blog : http://weblogs.asp.net/shijuvarghese Twitter : http://twitter.com/shijucv Email : shiju.varghese@gmail.com
2. Who Am I? Microsoft MVP on ASP.NET Solution Architect Focus on Microsoft Web Platform stack Agile Enthusiast Technology Consultant – Web Apps/ASP.NET MVC/EF Blog: http://weblogs.asp.net/shijuvarghese Twitter: @shijucv
4. New tools from Microsoft Web Platform Web Matrix IIS Express ASP.NET Web Pages SQL Server Compact Razor NuGet
5. Introduction to Razor A new view-engine option for ASP.NET A simplified syntax Its not a new language A code focused templating syntax optimized around HTML generation Shared by ASP.Netweb pages and ASP.Net MVC Works with any Text Editor IntelliSense with Visual Studio 2010/ VWD 2010 CSHTML (C#) and VBHTML (VB.NET) Unit Testable
6. ASP.NET Razor Support ASP.NET Web Pages Using for inline programming ASP.NET MVC 3 Using for ASP.NET MVC Views Tools Web Matrix Visual Studio 2010 Visual Web Developer 2010 Languages C# VB.Net
7. @ character @ character is using for insert server side code Single statement blocks @{ varmyMessage = "Hello World"; } Starts inline expressions <p>The value of myMessage is: @myMessage</p> Multi-statement blocks @{ var greeting = "Welcome to our Razor!"; varweekDay = DateTime.Now.DayOfWeek; vargreetingMessage = greeting + " Today is: " + weekDay; }
8. Razor Syntax Web Forms syntax <% for (int i = 0; i < 10; i++) { %> <li><% =i %></li> <% } %> Razor syntax @for (int i = 0; i < 10; i++) { <li>@i</li> }
9. Razor Syntax @{ var name = “Shiju”; var title=“Architect”; <div> Name: @name Title: @title </div> }
10. Layout page Share common html across many pages Layout page: _LayoutPage.cshtml <html> <title>@Page.Title</title> <body> <div> @Html.Partial("_Header") </div> @RenderBody() <div> @Html.Partial("_Footer")</div> </body>