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

Views

Total Views
16,312
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
45
Comments
0
Likes
8

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
  • There have been a lot of rumors floating around that ASP.NET Web Forms is dying and being replaced with ASP.NET MVC…you know, like the Web Forms Reaper is coming? Well….here I am!
  • It is up to you to decide how you want to get your data and how to define your objects. Although there are accepted guidelines on how to have good design, it is not decided for you with The ASP.Net MVC Framework.

Transcript

  • 1. rev 1.0/0111
    Getting Started withASP.NET MVC 3 and Razor
    Dan Wahlin
    http://www.TheWahlinGroup.com
  • 2. Contact Info
    Blog
    http://weblogs.asp.net/dwahlin
    Twitter
    @DanWahlin
    Email:
    dwahlin@theWahlinGroup.com
  • 3. rev 1.0/0111
    Agenda
    The MVC Pattern
    ASP.NET MVC 3
    Getting Started with Razor
    Demos
  • 4.
  • 5. MVC Pattern - A Conceptual View
    Decouples the backend business logic from the front end
    Model
    Binds the model and view together and selects which view to display next
    Data Transfer
    Request
    Controller
    Business InteractionLayer
    User InteractionLayer
    View
    Response
    Visualizes the application data supplied by the model
  • 6. Model
    Has business/domain logic
    ASP.NET MVC doesn’t tell you what to use:
    LINQ to SQL
    nHiberate
    Entity Framework
    PLINQO
    Custom/POCO object
    rev 1.0/0111
  • 7. View
    Should be “thin” and dumb
    No business logic
    Only Display logic / Transformation of data
    JavaScript is valid for client side - jQuery
    rev 1.0/0111
  • 8. Controller
    Should also be "thin"
    Controller has "Actions"
    Requests always come through the controller
    Decides what data is needed
    Tells which View to render
    Tells the View what "Model" render
    rev 1.0/0111
  • 9. rev 1.0/0111
    Agenda
    The MVC Pattern
    ASP.NET MVC 3
    Getting Started with Razor
    Demos
  • 10. What is ASP.NET MVC?
    ASP.NET MVC implements the Model-View-Controller pattern
    Provides an alternative to ASP.NET Web Forms
    Available from http://www.asp.net/mvc/mvc3
    rev 1.0/0111
    INTRODUCTION-10
  • 11. Goals of ASP.NET MVC Framework
    rev 1.0/0111
    • Clean url schemes (think SEO)
    • 12. Support existing ASP.NET runtime features
    • 13. 100% control over rendered HTML
    • 14. Testable by default (built with TDD in mind)
    • 15. Support third-party view engines
    • 16. Support static and dynamic languages
    • 17. Auto-mapping of form variables to object properties
    • 18. Built-in validation support
  • Key ASP.NET MVC 3 Features
    Razor View Engine
    .cshtml extension
    Dynamic ViewBag Property
    Global Filters
    JSON binding for Action Parameters
    Enhanced .NET 4 Validation Support
    Unobtrusive JavaScript for validation
    Layout Page
    Partial-Page Output Caching
    Support for Dependency Injection
    rev 1.0/0111
  • 19. ASP.NET MVC 3 Project Structure
    INTRODUCTION-13
    Controllers
    Razor Pages (Views)
    Model Classes
    "Master Page"
    rev 1.0/0111
  • 20. Steps to use ASP.NET MVC
    Create a controller class in the Controllers folder
    Add one or more Actions (methods) into the controller
    Right-click on an Action and select Add View from the menu
    rev 1.0/0111
  • 21. rev 1.0/0111
    Agenda
    The MVC Pattern
    ASP.NET MVC 3
    Getting Started with Razor
    Demos
  • 22. What is Razor?
    ASP.NET MVC 3 ships with a new View Engine called "Razor"
    Less markup transitions as compared to the ASP.NET Web Forms View Engine
    Provides a compact way to mingle code with markup
    Uses the @ character
    rev 1.0/0111
  • 23. Without Razor
    <ul>
    <%foreach (varcust in Customers) { %>
    <li><%: cust.Name%></li>
    <% } %>
    </ul>
    rev 1.0/0111
  • 24. With Razor
    <ul>
    @foreach (varcust in Customers) { <li>@cust.Name</li>
    }
    </ul>
    rev 1.0/0111
  • 25. Razor Fundamentals
    Razor provides a compact syntax for mixing "code" with markup:
    rev 1.0/0111
  • 26. Razor Example
    @model ProjectName.ViewModels.CustomerViewModel
    <fieldset>
    <legend>Customer Data</legend>
    <p>
    <label for="FirstName">First Name:</label>
    @Html.EditorFor(m => m.Customer.FirstName)
    @Html.ValidationMessageFor(m => m.Customer.FirstName, "*")
    </p>
    <p>
    <label for="LastName">Last Name:</label>
    @Html.EditorFor(m => m.Customer.LastName)
    @Html.ValidationMessageFor(m => m.Customer.LastName, "*")
    </p>
    </fieldset>
    rev 1.0/0111
  • 27. Razor Layout Pages
    Razor uses a _Layout.cshtml file as a "master page"
    _Layout.cshtml
    <html>
    <title>@ViewBag.Title</title>
    <body>
    @RenderBody()
    </body>
    </html>
    Index.cshtml@{
    ViewBag.Title= “Your Page Title”;
    }
    <div>Hello World!</div>
  • 28. Thanks!
    Blog
    http://weblogs.asp.net/dwahlin
    Twitter
    @DanWahlin
    Email:
    dwahlin@theWahlinGroup.com
  • 29. ASP.NET MVC 3 Demo Site
    Download an ASP.NET MVC 3 demo site from http://mvcmusicstore.codeplex.com
    rev 1.0/0111
  • 30. Razor Tools
    Web Forms View to Razor View Converter:https://github.com/telerik/razor-converter
    MVC 2 to MVC 3 Project Converterhttp://aspnet.codeplex.com/releases/view/59008
    rev 1.0/0111