Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Introduction to ASP.NET MVC Barry Gervin, Partner [email_address] @bgervin ObjectSharp.com/blogs/Barry
Objectives <ul><li>Why do we need something else? </li></ul><ul><ul><li>What’s wrong with Web Forms? </li></ul></ul><ul><l...
Agenda <ul><li>WebForms </li></ul><ul><li>MVC </li></ul><ul><li>ASP.NET MVC </li></ul><ul><ul><li>Tenets </li></ul></ul><u...
ASP.NET WEB FORMS
ASP.NET Then… ASP.NET One web application framework to rule them all… Caching Modules Handlers Intrinsics Pages Controls G...
WebForms ASPX Page User/Custom/Server Controls Master Page User/Custom/Server Controls Model
QUICK DEMO <ul><li>Pages, Events and Postbacks </li></ul>
Page Controller ASPX Page ASP.NET Response Request
No  real  role responsibility… Master Page UI Presentation Logic Business Logic Data Access Who does what? How and when? P...
Control abstractions  can be  negative…
It isn't  easy enough  to test… Logic UI
WebForms are great, but options are good…
ASP.NET MVC
ASP.NET Now… Presentation Runtime ASP.NET Dynamic Data ASP.NET WebForms ASP.NET MVC ASP.NET Core
So how does ASP.NET MVC differ?
MVC = Model-View-Controller Separation of concerns! Controller (Input) Model (Logic) View (Presentation)
ASP.NET MVC Model ASPX Page User/Custom/Server Controls Master Page User/Custom/Server Controls Controller
How does MVC look? Controller Handles input (HTTP requests) View Visually represents the model Request View Controller Res...
Framework Goals <ul><li>Alternative  </li></ul><ul><li>Frictionless   Testability </li></ul><ul><li>Tight control over <ma...
Project Structure Routes Views/Master Views/Master Models Controllers
ASP.NET MVC DEMO <ul><li>Routes, Controllers & Views </li></ul>
ASP.NET MVC doesn’t have… <ul><li>Postbacks </li></ul><ul><li>View state </li></ul><ul><li>Control state </li></ul><ul><li...
ASP.NET MVC still has… <ul><li>Web designer </li></ul><ul><li>Master pages </li></ul><ul><li>User controls </li></ul><ul><...
Routing
<ul><li>mysite.com/object/action/parameter </li></ul>
Clean URLs <ul><li>Don’t settle for… </li></ul><ul><li>/Products.aspx?CategoryID=123 </li></ul><ul><li>When you can easily...
Routing      protected   void  Application_Start( object  sender,  EventArgs  e)       {           RouteTable.Routes.Add( ...
Controller Conventions <ul><li>Controller </li></ul><ul><ul><li>Must… </li></ul></ul><ul><ul><ul><li>Be suffixed with “Con...
REAL WORLD WALKTHROUGH <ul><li>SayITFirst.ca </li></ul>
Extensibility Pipeline * ViewResult Controller Builder Controller Factory Controller View Engine View Locator View Control...
Action Results <ul><li>ActionResult </li></ul><ul><ul><li>ContentResult </li></ul></ul><ul><ul><li>EmptyResult </li></ul><...
Action Filters <ul><li>IActionFilter </li></ul><ul><ul><li>Controller </li></ul></ul><ul><ul><li>ActionFilterAttribute </l...
Controller Factory <ul><li>IControllerFactory </li></ul><ul><ul><li>DefaultControllerFactory </li></ul></ul>Controller Bui...
View Engine <ul><li>IViewEngine </li></ul><ul><ul><li>WebFormViewEngine </li></ul></ul><ul><li>IViewLocator </li></ul><ul>...
ASP.NET MVC 2 <ul><li>A good number of new features including: </li></ul><ul><ul><li>Client-side validation  based on the ...
Microsoft.com/web
Web Platform Installer
NerdDinner (nerddinner.com)
Professional  ASP.NET MVC 1.0, a.k.a. The “Gang of Foreheads” Book
ASP.NET MVC  in Action @ManningBooks
Pro ASP.NET MVC Framework (Highest rating on Amazon.com)
The Official ASP.NET MVC Site ASP.NET/MVC
You’ve Been Haacked (Phil Haack)  Haacked.com
Scott Hanselman’s Blog Hanselman.com
ObjectSharp.com
Resources <ul><li>Microsoft Starting Points </li></ul><ul><li>http://microsoft.com/web </li></ul><ul><li>http ://asp.net/m...
Summary <ul><li>Web Forms vs. MVC </li></ul><ul><li>101 How-To </li></ul><ul><li>Real World ASP.NET MVC </li></ul><ul><li>...
Location 1 Yonge Street Suite 1801 Toronto, ON M5E1W7 Julie James Training Manager Tel: 416-216-4603 Contacts Gisele Bourq...
Upcoming SlideShare
Loading in …5
×

CTTDNUG ASP.NET MVC

9,055 views

Published on

CTTDNUG ASP.NET MVC

CTTDNUG ASP.NET MVC

  1. 1. Introduction to ASP.NET MVC Barry Gervin, Partner [email_address] @bgervin ObjectSharp.com/blogs/Barry
  2. 2. Objectives <ul><li>Why do we need something else? </li></ul><ul><ul><li>What’s wrong with Web Forms? </li></ul></ul><ul><li>“ How To” build ASP.NET MVC </li></ul><ul><ul><li>How does this compare? Help? </li></ul></ul><ul><li>What should I beware of? </li></ul>
  3. 3. Agenda <ul><li>WebForms </li></ul><ul><li>MVC </li></ul><ul><li>ASP.NET MVC </li></ul><ul><ul><li>Tenets </li></ul></ul><ul><li>WebForms Vs. MVC </li></ul><ul><li>Walkthrough Real Application </li></ul><ul><li>Testing MVC </li></ul><ul><li>Extensibility </li></ul>
  4. 4. ASP.NET WEB FORMS
  5. 5. ASP.NET Then… ASP.NET One web application framework to rule them all… Caching Modules Handlers Intrinsics Pages Controls Globalization Profile Master Pages Membership Roles Etc.
  6. 6. WebForms ASPX Page User/Custom/Server Controls Master Page User/Custom/Server Controls Model
  7. 7. QUICK DEMO <ul><li>Pages, Events and Postbacks </li></ul>
  8. 8. Page Controller ASPX Page ASP.NET Response Request
  9. 9. No real role responsibility… Master Page UI Presentation Logic Business Logic Data Access Who does what? How and when? Page Control Control Control Control Control Control Control Control
  10. 10. Control abstractions can be negative…
  11. 11. It isn't easy enough to test… Logic UI
  12. 12. WebForms are great, but options are good…
  13. 13. ASP.NET MVC
  14. 14. ASP.NET Now… Presentation Runtime ASP.NET Dynamic Data ASP.NET WebForms ASP.NET MVC ASP.NET Core
  15. 15. So how does ASP.NET MVC differ?
  16. 16. MVC = Model-View-Controller Separation of concerns! Controller (Input) Model (Logic) View (Presentation)
  17. 17. ASP.NET MVC Model ASPX Page User/Custom/Server Controls Master Page User/Custom/Server Controls Controller
  18. 18. How does MVC look? Controller Handles input (HTTP requests) View Visually represents the model Request View Controller Response
  19. 19. Framework Goals <ul><li>Alternative </li></ul><ul><li>Frictionless Testability </li></ul><ul><li>Tight control over <markup> </li></ul><ul><li>Leverage the benefits of ASP.NET </li></ul><ul><li>Routable Urls to Controllers to Views </li></ul><ul><li>Conventions and guidance </li></ul><ul><li>Modular and Extensible </li></ul>
  20. 20. Project Structure Routes Views/Master Views/Master Models Controllers
  21. 21. ASP.NET MVC DEMO <ul><li>Routes, Controllers & Views </li></ul>
  22. 22. ASP.NET MVC doesn’t have… <ul><li>Postbacks </li></ul><ul><li>View state </li></ul><ul><li>Control state </li></ul><ul><li>Server-side form </li></ul><ul><li>Page/Control lifecycle </li></ul>
  23. 23. ASP.NET MVC still has… <ul><li>Web designer </li></ul><ul><li>Master pages </li></ul><ul><li>User controls </li></ul><ul><li>Membership/Roles/Profile </li></ul><ul><li>Globalization </li></ul><ul><li>Caching </li></ul><ul><li>HTTP intrinsics: </li></ul><ul><ul><li>HttpContext </li></ul></ul><ul><ul><li>HttpRequest </li></ul></ul><ul><ul><li>HttpResponse </li></ul></ul><ul><ul><li>Etc. </li></ul></ul>
  24. 24. Routing
  25. 25. <ul><li>mysite.com/object/action/parameter </li></ul>
  26. 26. Clean URLs <ul><li>Don’t settle for… </li></ul><ul><li>/Products.aspx?CategoryID=123 </li></ul><ul><li>When you can easily have… </li></ul><ul><li>/Product/Puppies </li></ul><ul><li>Or whatever else makes sense… </li></ul>
  27. 27. Routing     protected void Application_Start( object sender, EventArgs e)     {         RouteTable.Routes.Add( &quot;SearchRoute&quot; , new Route ( &quot;search/{searchterm}&quot; , new WebFormRouteHandler ( &quot;~/search.aspx&quot; )));         RouteTable.Routes.Add( &quot;UserRoute&quot; , new Route( &quot;users/{username}&quot; , new WebFormRouteHandler ( &quot;~/users.aspx&quot; )));     } ....    protected void Page_Load( object sender, EventArgs e)       {           string searchterm= Page.RouteData.Values[ &quot;searchterm&quot; ] as string ;           Response.Write(searchterm);       } ...   < asp : HyperLink ID =&quot;HyperLink1&quot; runat =&quot;server&quot; NavigateUrl =&quot; <%$RouteUrl:SearchTerm=Bob%> &quot; > Link to search </ asp : HyperLink >
  28. 28. Controller Conventions <ul><li>Controller </li></ul><ul><ul><li>Must… </li></ul></ul><ul><ul><ul><li>Be suffixed with “Controller” </li></ul></ul></ul><ul><ul><ul><li>Implement IController (or inherit from Controller) </li></ul></ul></ul><ul><li>Action </li></ul><ul><ul><li>Must… </li></ul></ul><ul><ul><ul><li>Be Public </li></ul></ul></ul><ul><ul><ul><li>Return ActionResult or void </li></ul></ul></ul><ul><ul><li>Can’t… </li></ul></ul><ul><ul><ul><li>Be generic </li></ul></ul></ul><ul><ul><ul><li>Have a NonActionAttribute </li></ul></ul></ul><ul><ul><ul><li>Have out/ref parameters </li></ul></ul></ul>
  29. 29. REAL WORLD WALKTHROUGH <ul><li>SayITFirst.ca </li></ul>
  30. 30. Extensibility Pipeline * ViewResult Controller Builder Controller Factory Controller View Engine View Locator View Controller Action Invoker Action Result* Action Filters
  31. 31. Action Results <ul><li>ActionResult </li></ul><ul><ul><li>ContentResult </li></ul></ul><ul><ul><li>EmptyResult </li></ul></ul><ul><ul><li>JsonResult </li></ul></ul><ul><ul><li>RedirectResult </li></ul></ul><ul><ul><li>RedirectToRouteResult </li></ul></ul><ul><ul><li>ViewResult </li></ul></ul>Controller Controller Action Invoker Action Result
  32. 32. Action Filters <ul><li>IActionFilter </li></ul><ul><ul><li>Controller </li></ul></ul><ul><ul><li>ActionFilterAttribute </li></ul></ul><ul><li>OnActionExecuting </li></ul><ul><li>[Action Method Executed] </li></ul><ul><li>OnActionExecuted </li></ul><ul><li>OnResultExecuting </li></ul><ul><li>[Action Result Executed] </li></ul><ul><li>OnResultExecuted </li></ul>
  33. 33. Controller Factory <ul><li>IControllerFactory </li></ul><ul><ul><li>DefaultControllerFactory </li></ul></ul>Controller Builder Controller Factory Controller
  34. 34. View Engine <ul><li>IViewEngine </li></ul><ul><ul><li>WebFormViewEngine </li></ul></ul><ul><li>IViewLocator </li></ul><ul><ul><li>ViewLocator </li></ul></ul><ul><ul><ul><li>WebFormViewLocator </li></ul></ul></ul>View Engine View Locator View Action Result*
  35. 35. ASP.NET MVC 2 <ul><li>A good number of new features including: </li></ul><ul><ul><li>Client-side validation based on the model’s validation metadata </li></ul></ul><ul><ul><li>Areas to better organize an application </li></ul></ul><ul><ul><li>Model validation providers to hook in alternative validation logic when model binding </li></ul></ul><ul><ul><li>Metadata providers to allow for alternative sources of metadata for model objects </li></ul></ul>
  36. 36. Microsoft.com/web
  37. 37. Web Platform Installer
  38. 38. NerdDinner (nerddinner.com)
  39. 39. Professional ASP.NET MVC 1.0, a.k.a. The “Gang of Foreheads” Book
  40. 40. ASP.NET MVC in Action @ManningBooks
  41. 41. Pro ASP.NET MVC Framework (Highest rating on Amazon.com)
  42. 42. The Official ASP.NET MVC Site ASP.NET/MVC
  43. 43. You’ve Been Haacked (Phil Haack) Haacked.com
  44. 44. Scott Hanselman’s Blog Hanselman.com
  45. 45. ObjectSharp.com
  46. 46. Resources <ul><li>Microsoft Starting Points </li></ul><ul><li>http://microsoft.com/web </li></ul><ul><li>http ://asp.net/mvc </li></ul><ul><li>http://codeplex.com/MVCContrib </li></ul><ul><li>http://aspnet.codeplex.com </li></ul><ul><li>Community Starting Points </li></ul><ul><li>http:// channel9.msdn.com/tags/asp.net+mvc </li></ul><ul><li>http://haacked.com / </li></ul><ul><li>http://stackoverflow.com </li></ul>
  47. 47. Summary <ul><li>Web Forms vs. MVC </li></ul><ul><li>101 How-To </li></ul><ul><li>Real World ASP.NET MVC </li></ul><ul><li>Testability </li></ul>
  48. 48. Location 1 Yonge Street Suite 1801 Toronto, ON M5E1W7 Julie James Training Manager Tel: 416-216-4603 Contacts Gisele Bourque Client Services Manager Tel: 416-216-4603

×