1 / 14

ASP.NET MVC

ASP.NET MVC. John Clayton http://codemonkeylabs.com/. What is ASP.NET MVC?. MVC == Model, View, Controller Model: The concrete ‘things’ you are working on View: The output rendered to the client Controller: Where the logic lives Gives you complete control over URLs and markup

komala
Télécharger la présentation

ASP.NET MVC

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASP.NET MVC John Clayton http://codemonkeylabs.com/

  2. What is ASP.NET MVC? • MVC == Model, View, Controller • Model: The concrete ‘things’ you are working on • View: The output rendered to the client • Controller: Where the logic lives • Gives you complete control over URLs and markup • Build AJAX applications with speed and ease • Easily extensible at any point of the request • Make it do what you want • Designed with automated testing in mind • Because we’re all human

  3. What about Web Forms? • Web Forms isn’t going away  • Improvements in ASP.NET 4.0 will make it easier for Web Forms and MVC to coexist • Web Forms & MVC are both rendering engines on top of the ASP.NET runtime • MVC uses the Web Forms engine by default

  4. How it works • When a request comes in it is matched against a route • The route provides a route handler • The route handler provides a controller • An action in the controller does the work and provides an action result • The action result is executed to return content to the client • Any part of this can easily be extended and tested!

  5. Routes • Routes are the entry point to the application • In Web Forms a file on disk is the entry point • Routes are defined at startup • Routes define a parameterized URL, a route handler, default values, constraints, and an optional name • Routing works both ways • Route data can be built from a URL • A URL can be built from route data

  6. Routes

  7. Route Handlers • Created by the current route • Single purpose: create an IHttpHandler • In the case of MVC it creates an instance of an MvcHandler

  8. Controller Factory • Single responsibility: Given the route data, create a controller • The default controller factory automagically finds your controllers based on convention by scanning loaded assemblies looking for classes that… • Are public • Name ends with ‘Controller’ • Are not abstract • Is assignable to IController

  9. Controller & Actions • The controller is little more than a class containing actions • Actions are all public methods on a controller (usually) • Actions should return an ActionResult • Controllers and Actions can be decorated with filters to customize this step • Validation, authorization, error handling, output caching, ignoring a public method, & filtering by HTTP method come in the box to name a few • Extensible by implementing some basic interfaces

  10. Controllers & Actions

  11. View Engines & Views • The View Engine takes the data from the Action and renders the output • View Engines are pluggable • The default View Engine uses Web Forms • Uses the rendering engine only • No ViewState • View files are found via convention • Unless specified, the ‘Index’ Action of the ‘Home’ Controller will start looking for the View at ~/Views/Home/Index.aspx

  12. MVC vs. Web Forms or • Both get you from A to B, but MVC is a much more raw, hands-on experience • Web Forms abstracts much of web development from the programmer • After a slight learning curve you won’t look back

  13. Where do I get it? • ASP.NET MVC v1 available as an add-on for Visual Studio 2008 • Requires .NET 3.5 SP1 • ASP.NET MVC v2 is currently in RC2 and will likely ship very soon • Will work both with .NET 3.5 SP1 and .NET 4.0 • Will come ‘in the box’ with Visual Studio 2010

  14. Resources • http://www.asp.net/mvc/ • http://aspnet.codeplex.com/ • http://stackoverflow.com/

More Related