SlideShare a Scribd company logo
1 of 40
The ASP.NET MVC Framework Jess Chadwick Independent Consultant Microsoft MVP,  ASPInsider
We thank the following companies for their gracious sponsorship Platinum Sponsors Gold Sponsor
Agenda What is ASP.NET MVC? Overview / Goals Quick demo The Pattern AJAX-ifying your MVC app Testability Advanced Features
What is ASP.NET MVC? Microsoft’s ASP.NET implementation of the MVC software pattern More control over your HTML and URLs More easily testable framework A new Web Project type for ASP.NET An option / alternative
DEMO:  MVC Hello World Let’s whet the appetite!
What’s the Point? This is not “Web Forms v.Next” All about alternatives Flexibility Extend it… or not Create your own Controller- and View- Engines or use others such as Brail or NHaml Fundamental Part of System.Web namespace Fully supported KISS  &  DRY
Driving Goals Separation of Concerns Easy testing & TDD Highly-maintainable applications Extensible and Pluggable Plug in what you need Build your own custom build
Driving Goals (cont’d) Clean URLs and HTML SEO and REST friendly Great interaction with ASP.NET Handlers, Modules, Providers, etc. still work .ASPX, .ASCX, .MASTER pages Visual Studio ASP.NET Designer surface
So, what is it?
The Pattern
The Model “The center of the universe” This represents your core business domain…AKA – your “bread and butter” Preferably independent of any specific technology
Views ,[object Object]
Are pretty “stupid”
Web Forms as default ViewEngine
.ASPX, .ASCX, .MASTER, etc.
Html Helpers for rendering markup
Can replace with other view technologies:
Template engines (NVelocity, Brail, …).
Output formats (images, RSS, JSON, …).
Mock out for testing.
Can use loosely typed or strongly typed data,[object Object]
ASP.NET MVC  vs. Web Forms Data View(ASPX)--------------Controller (Code-Behind) ASP.NET Web Forms (Page Controller) Model List View Detail View Product Controller ASP.NET MVC  (Front Controller) Data Model
The MVC Pattern in action ,[object Object]
Route is determined
Controller is activated
Method (Action) on Controller is invoked
Controller does some stuff
Renders View, passing in         custom ViewData
URLs are rendered,   pointing to other  Controllers,[object Object]
URL Routing Developers add Routes to a global RouteTable Mapping creates a RouteData - a bag of key/values routes.MapRoute(     "blog/bydate/{year}/{month}/{day}",     new { controller = “blog”, action = “show” },     Constraints = new RouteValueDictionary {            {"year", @"{1.4}"},        {"month", @"{1.2}"},        {"day", @"{1.2}"}}   })
URL Routing (cont’d) Separate assembly, not closely tied/related to ASP.NET MVC
DEMO: Online Catalog Sample
Using ASP.NET MVC to Create Rich Web Experiences I don’t care if “Web 2.0” is a cliché!
ASP.NET MVC:  User Controls Isolate reusable view components (Not  the logic to retrieve the data!)
DEMO Adding User Controlsto Your Views This should be nothing new, but it does prepare us for bigger and better things…
ASP.NET MVC:  Partial Rendering You can render user controls: As part of a page, or… Down the wire by themselves!
DEMO:  AJAX-ifying the Online Catalog Sample
Testability “What!?  I can mock out HttpContext!?”
Designed for Testability MockableIntrinsics HttpContextBase, HttpResponseBase, HttpRequestBase Extensibility  IController IControllerFactory IRouteHandler ViewEngineBase
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 repository = new TestPostRepository(); TestViewEngineviewEngine = new TestViewEngine(); BlogController controller = new BlogController(…); var result = controller.ShowPost(2) as ViewResult; Assert.AreEqual("showpost",result.ViewName); Assert.IsTrue(repository.GetPostByIdWasCalled); Assert.AreEqual(2, repository.LastRequestedPostId); }

More Related Content

Recently uploaded

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Introduction To ASP.NET MVC

  • 1. The ASP.NET MVC Framework Jess Chadwick Independent Consultant Microsoft MVP, ASPInsider
  • 2. We thank the following companies for their gracious sponsorship Platinum Sponsors Gold Sponsor
  • 3. Agenda What is ASP.NET MVC? Overview / Goals Quick demo The Pattern AJAX-ifying your MVC app Testability Advanced Features
  • 4. What is ASP.NET MVC? Microsoft’s ASP.NET implementation of the MVC software pattern More control over your HTML and URLs More easily testable framework A new Web Project type for ASP.NET An option / alternative
  • 5. DEMO: MVC Hello World Let’s whet the appetite!
  • 6. What’s the Point? This is not “Web Forms v.Next” All about alternatives Flexibility Extend it… or not Create your own Controller- and View- Engines or use others such as Brail or NHaml Fundamental Part of System.Web namespace Fully supported KISS & DRY
  • 7. Driving Goals Separation of Concerns Easy testing & TDD Highly-maintainable applications Extensible and Pluggable Plug in what you need Build your own custom build
  • 8. Driving Goals (cont’d) Clean URLs and HTML SEO and REST friendly Great interaction with ASP.NET Handlers, Modules, Providers, etc. still work .ASPX, .ASCX, .MASTER pages Visual Studio ASP.NET Designer surface
  • 11. The Model “The center of the universe” This represents your core business domain…AKA – your “bread and butter” Preferably independent of any specific technology
  • 12.
  • 14. Web Forms as default ViewEngine
  • 16. Html Helpers for rendering markup
  • 17. Can replace with other view technologies:
  • 19. Output formats (images, RSS, JSON, …).
  • 20. Mock out for testing.
  • 21.
  • 22. ASP.NET MVC vs. Web Forms Data View(ASPX)--------------Controller (Code-Behind) ASP.NET Web Forms (Page Controller) Model List View Detail View Product Controller ASP.NET MVC (Front Controller) Data Model
  • 23.
  • 26. Method (Action) on Controller is invoked
  • 28. Renders View, passing in custom ViewData
  • 29.
  • 30. URL Routing Developers add Routes to a global RouteTable Mapping creates a RouteData - a bag of key/values routes.MapRoute( "blog/bydate/{year}/{month}/{day}", new { controller = “blog”, action = “show” }, Constraints = new RouteValueDictionary { {"year", @"{1.4}"}, {"month", @"{1.2}"}, {"day", @"{1.2}"}} })
  • 31. URL Routing (cont’d) Separate assembly, not closely tied/related to ASP.NET MVC
  • 33. Using ASP.NET MVC to Create Rich Web Experiences I don’t care if “Web 2.0” is a cliché!
  • 34. ASP.NET MVC: User Controls Isolate reusable view components (Not the logic to retrieve the data!)
  • 35. DEMO Adding User Controlsto Your Views This should be nothing new, but it does prepare us for bigger and better things…
  • 36. ASP.NET MVC: Partial Rendering You can render user controls: As part of a page, or… Down the wire by themselves!
  • 37. DEMO: AJAX-ifying the Online Catalog Sample
  • 38. Testability “What!? I can mock out HttpContext!?”
  • 39. Designed for Testability MockableIntrinsics HttpContextBase, HttpResponseBase, HttpRequestBase Extensibility IController IControllerFactory IRouteHandler ViewEngineBase
  • 40. 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 repository = new TestPostRepository(); TestViewEngineviewEngine = new TestViewEngine(); BlogController controller = new BlogController(…); var result = controller.ShowPost(2) as ViewResult; Assert.AreEqual("showpost",result.ViewName); Assert.IsTrue(repository.GetPostByIdWasCalled); Assert.AreEqual(2, repository.LastRequestedPostId); }
  • 41. DEMO: Test-Driven Development “Wasn’t this supposed to come first?”
  • 42.
  • 46.
  • 47. Extensibility Views Controllers Models Routes …all Pluggable
  • 48. ViewEngineBase View Engines render output You get WebForms by default Can implement your own MVCContrib has ones for Brail, Nvelocity NHaml is an interesting one to watch View Engines can be used to Offer new DSLs to make HTML easier Generate totally different mime/types Images, RSS, JSON, XML, OFX, VCards, whatever.
  • 49. Example View: Web Forms <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="List.aspx" Inherits="MvcApplication5.Views.Products.List" Title="Products" %> <asp:ContentContentPlaceHolderID="MainContentPlaceHolder" runat="server"> <h2><%= ViewData.CategoryName %></h2> <ul> <% foreach (var product in ViewData.Products) { %> <li> <%= product.ProductName %> <div class="editlink"> (<%= Html.ActionLink("Edit", new { Action="Edit", ID=product.ProductID })%>) </div> </li> <% } %> </ul> <%= Html.ActionLink("Add New Product", new { Action="New" }) %> </asp:Content>
  • 50. Example View: NHaml %h2= ViewData.CategoryName%ul - foreach (var product in ViewData.Products) %li = product.ProductName .editlink = Html.ActionLink("Edit", new { Action="Edit", ID=product.ProductID }) = Html.ActionLink("Add New Product", new { Action="New" })
  • 51. Example View: Spark <h2>${CategoryName}</h2> <viewdata products="IEnumerable[[Product]]"/> <ul if="products.Any()"> <li each="var p in products">${p.Name}</li> </ul> <else> <p>No products available</p> </else>
  • 52. Demo: Filters and View Engines Now we can really take control!
  • 53. What’s the Point? This is not “Web Forms v.Next” All about alternatives Flexibility Extend it… or not Create your own Controller- and ViewEngines, or use others such as Brail or NHaml Fundamental Part of System.Web namespace Fully supported KISS & DRY
  • 55. Relevant Sessions Today Extending ASP.NET MVC w/ MVCContribJohn Zablocki Noon – 1 PM Ignite Your MVC Application with Spark View EngineCurtis Mitchell 4PM – 5:15 PM
  • 56. Resources The Bits ASP.NET MVC: http://asp.net/MVC MVCContrib: http://www.codeplex.com/MVCContrib Quickstart http://quickstarts.asp.net/3-5-extensions/mvc/default.aspx Videos ASP.NET: http://www.asp.net/learn/3.5-extensions-videos/ MIX: http://sessions.visitmix.com Community/Blogs ASP.NET Forums: http://forums.asp.net/1146.aspx Scott Guthrie (ScottGu): http://weblogs.asp.net/scottgu/ Scott Hanselman: http://www.hanselman.com/blog/ Phil Haack: http://haacked.com/ Sample Apps MVC Samples: http://www.codeplex.com/mvcsamples CodeCampServer: http://codecampserver.org Jess Chadwick Independent Consultant Microsoft MVP, ASPInsider jesschadwick@gmail.com http://blog.jesschadwick.com