Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jess Chadwick Lead Code Monkey Infragistics Website Team Todd Snyder Development Team Lead Infragistics Experience Design Group.

Similar presentations


Presentation on theme: "Jess Chadwick Lead Code Monkey Infragistics Website Team Todd Snyder Development Team Lead Infragistics Experience Design Group."— Presentation transcript:

1 Jess Chadwick Lead Code Monkey Infragistics Website Team Todd Snyder Development Team Lead Infragistics Experience Design Group

2 Model – View - Controller Model Controller View

3 Controller – The Traffic Cop  Handles User Input  Interacts with Model/Data  Select View to Render

4 Controllers MVC - WebForm

5 ASP.NET Page Lifecycle

6 Request Flow Request HTTP Routing Route Route Handler Http Handler Controller View Engine View Response

7 Controllers – Page Routing

8 Controllers – Actions

9 Controllers – Defining Actions

10 Controllers – Parameters  RouteData: Contains Name/Value Pairs  Form, Query String, and/or Cookie  Missing Reference/Nullable Types set to null  Nullable optional parameters  Base class: Request and Response Methods

11 Controllers – Action Results  ViewResult  RedirectResult  RedirectToRouteResult  ContentResult  JsonResult  EmptyResult

12 Controllers – Attributes  PrincipalPermission  NonAction  ActionFilter

13 Controllers – Action Filters  Attach additional behaviors to actions  Before & After Action Execution  Before & After Result Execution  Useful for logging, compression, etc.

14 Controllers – Unit Testing

15 Testing Controller Actions  No requirement to test within ASP.NET runtime!  Use RhinoMocks, TypeMock, Moq, etc.  Create Test versions of the parts of the runtime you want to stub [TestMethod] public void ShowPostsDisplayPostView() { TestPostRepository rep = new TestPostRepository(); BlogController controller = new BlogController(rep); var result = controller.ShowPost(2); Assert.AreEqual("showpost", result.ViewName); Assert.IsTrue(repository.GetPostByIdWasCalled); Assert.AreEqual(2, repository.LastRequestedPostId); } [TestMethod] public void ShowPostsDisplayPostView() { TestPostRepository rep = new TestPostRepository(); BlogController controller = new BlogController(rep); var result = controller.ShowPost(2); Assert.AreEqual("showpost", result.ViewName); Assert.IsTrue(repository.GetPostByIdWasCalled); Assert.AreEqual(2, repository.LastRequestedPostId); }

16 ASP.NET MVC: Views

17 Model – View - Controller Model Controller View

18 Views – What are they?  Render output  Usually pretty “stupid”

19 It’s all about the “ViewData” Views - Working with Data

20 Views - Strongly-Typed Data  Inherits ViewPage  DEMO: Strongly-Typed View

21 Views - Weakly-Typed Data  Inherits ViewPage  DEMO: Weakly-Typed View

22 “I can see!” View Engines

23 View Engines - Definition  Figure out how to render the markup  View Locator finds the template  Pluggable  Web Forms, Nvelocity, Brail, Nhaml, etc.  Roll your own  Implement IViewEngine

24 View Engines - WebFormViewEngine  Default engine based on Web Forms markup  Familiar Environment  Layout:.master  Content:.aspx  User Controls:.ascx

25 View Engines - WebFormViewLocator  Standard, default layout: /Views /{Controller Name} /*.aspx /*.ascx /Shared /*.master /*.aspx /*.ascx

26 Think of them as your personal assistants. UI Helpers

27 Why do we need UI Helpers?  More control = less done for you  Avoid writing “boring” markup  Encapsulate what varies  Replace Web Forms server controls

28 Extension Methods Revisited  New.NET 3.0 feature  Static Methods posing as built-in behavior  Make your life a whole lot easier  Allow easy extensibility!

29 UI Helpers - Common/Useful Helpers Form HelpersUrl/Link/Content Helpers  Html.Hidden()  Html.TextBox()  Html.TextArea()  Html.RadioButton()  Html.RadioButtonList()  Html.DropDownList() method(name, value, attributes)  Html.ActionLink ()  Html.RouteLink()  Html.Encode()  Html.AttributeEncode()  Url.Action()  Url.RouteUrl()  Url.Encode(contentPath)  Url.Content(contentPath)

30 No, not … Back to basics! DEMO: Working with Forms

31 Rendering Components

32 User Controls  Extension Methods  Html.RenderUserControl(virtualPath)  Html.RenderUserControl(virtualPath, data)  Server Controls  Traditional Web Forms style!  Third-Party Controls  DEMO: Create and use a user control

33 Enriching the Client Experience

34 ASP.NET AJAX? Nope!

35 Filling the Gap  Roll your own  Popular Frameworks  jQuery  prototype  JavaScriptMVC  Rico  script.aculo.us  ASP.NET AJAX (client library)  DEMO: MVC & ASP.NET AJAX

36 Jess Chadwick Email: jesschadwick@gmail.comjesschadwick@gmail.com Blog: http://blog.jesschadwick.comhttp://blog.jesschadwick.com Todd Snyder Email: tsnyder@infragistics.comtsnyder@infragistics.com Blog: http://blogs.infragistics.com/blogs/tsnyderhttp://blogs.infragistics.com/blogs/tsnyder

37  The Bits  ASP.NET MVC Preview 3: http://asp.net/MVChttp://asp.net/MVC  ASP.NET MVC Source Code: http://www.codeplex.com/aspnethttp://www.codeplex.com/aspnet  Quickstart  http://quickstarts.asp.net/3-5-extensions/mvc/default.aspx http://quickstarts.asp.net/3-5-extensions/mvc/default.aspx  Videos  ASP.NET: http://www.asp.net/learn/3.5-extensions-videos/http://www.asp.net/learn/3.5-extensions-videos/  MIX: http://sessions.visitmix.comhttp://sessions.visitmix.com  Community/Blogs  ASP.NET Forums: http://forums.asp.net/1146.aspx http://forums.asp.net/1146.aspx  Scott Guthrie (ScottGu): http://weblogs.asp.net/scottgu/http://weblogs.asp.net/scottgu/  Scott Hanselman: http://www.hanselman.com/blog/http://www.hanselman.com/blog/  Phil Haack: http://haacked.com/http://haacked.com/  Sample Apps  MVC Samples: http://www.codeplex.com/mvcsampleshttp://www.codeplex.com/mvcsamples  CodeCampServer: http://codecampserver.orghttp://codecampserver.org Jess Chadwick jesschadwick@gmail.com http://blog.jesschadwick.com Todd Snyder tsnyder@infragistics.com http://blogs.infragistics.com/blogs/tsnyder Resources


Download ppt "Jess Chadwick Lead Code Monkey Infragistics Website Team Todd Snyder Development Team Lead Infragistics Experience Design Group."

Similar presentations


Ads by Google