Introducing Razor - A new view engine for ASP.NET

  • 3,642 views
Uploaded on

An Introducing to Razor view engine for ASP.NET

An Introducing to Razor view engine for ASP.NET

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
3,642
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
148
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 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
  • 3. Session Objectives
    Introduction to Razor
    Introduction to Razor Syntax
    Demonstrate Razor syntax in ASP.NET MVC 3 Views
  • 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>
  • 11. Using Layout page
    @{
    Page.Title = “Your Page Title”;
    Layout = "_Layout.cshtml";
    }
  • 12. _PageStart.cshtml
    Run code for each page
    Setup layout page for an entire folder
  • 13. Using Helper
    App_Code/RazorHelper.cshtml
    @helper ShowCopyright() {
    <div>
    Copyright Shiju Varghese @DateTime.Now.Year
    </div>
    Using a Helper
    @RazorHelper.ShowCopyright()
  • 14. Demo
  • 15. Thanks