SlideShare a Scribd company logo
1 of 34
Download to read offline
Introduction to ASP.NET MVC 2 Joe Wilson Volare Systems, Inc. Email: joe@volaresystems.com Blog: http://VolareSystems.com/Blog Twitter: joe_in_denver
Agenda What is MVC? What are the benefits of MVC? Code walkthroughs Drawbacks of MVC Future of MVC Resources
Quick Audience Poll Who has used Web Forms and not MVC? Who has used MVC?
Where does MVC fit? Web Forms MVC ASP.NET (Request, Response, Session,  Cookies, QueryString, Master Pages)
What is MVC?  M= Model V= View C= Controller
What is MVC? – Views Are .ASPX and .ASCX files Inherit from ViewPage Holds user interface elements (HTML, CSS, JavaScript) Views should not contain much logic Simple “if”s or “foreach”es are OK
What is MVC? – Controllers Are .CS files Inherit from Controller Code is in Actions (methods) Validate user input before moving on Works with Models for small logic and data access Render Views, JSON, XML, File, etc.
What is MVC? – Models Are .CS files and just POCOs MVC doesn’t dictate how to set up Models Data to display in the View or post from the View back to the Controller Good place for validation attributes Good place for light, display-related logic (FullName, Totals, IsUserLoggedIn, etc.)
What about a bigger MVC project? http://whocanhelpme.codeplex.com
How Web Forms Works Event Based OnPreRender, OnLoad Page http://server/ProductEdit.aspx Request Response HTML, JSON, File, XML
How MVC Works Route Based   Controller/Action Action Controller http://server/product/edit Request Response HTML, JSON, File, XML
How MVC Works Request (GET or POST) Routing Engine Controller (Action) Response View, JSON, File, XML Model
MVC Conventions Action Controller http://server/product/edit View Folder
What are the benefits of MVC? Benefit: Separation of Concerns guidance MVC gives guidance about what kind of code goes where Convention over configuration Don’t dump all your code in Page_Load and Button_Click
What are the benefits of MVC? Style Sheets, Images Controllers Models JavaScript Views Master Pages Tests
What are the benefits of MVC? Benefit: Testability MVC allows creation of a new Controller inside a test Web Forms code behind files are hard to test because HttpContext is hard to mock
What are the benefits of MVC? Benefit: Clean HTML MVC controls keep their IDs Easier to navigate with JavaScript and jQuery Easier to build XHTML and Section 508 compliant sites (use W3C Validators and Section508.info to check)
What are the benefits of MVC? HTML from Web Forms <span id="ctl00_MainContent_uxdPHAllContent_TripSelector_lblFromDate"> From Date:</span> <input type="text" name="ctl00$MainContent$uxdPHAllContent$TripSelector$txtFromDate" id="ctl00_MainContent_uxdPHAllContent_TripSelector_txtFromDate" /> HTML from MVC <label for="FromDate">From Date:</label> <input type="text"name="FromDate"id="FromDate" />
What are the benefits of MVC? Benefit: Clean URLs MVC has more hackable, SEO-friendly URLs URLs without query strings
What are the benefits of MVC? URLs for ASP.NET Web Forms http://mysite.com/Shop.aspx?Category=Shirts http://mysite.com/Shop.aspx?ID=123 URLs for ASP.NET MVC http://mysite.com/Shop/Category/Shirts http://mysite.com/Shop/ID/123
What are the benefits of MVC? Benefit: Headroom Extensible for changing  Routing View Engine Model Binders All code is released as open source ,[object Object]
Controller Factories,[object Object]
What are the benefits of MVC? Benefit: Can run alongside Web Forms Don’t have to wait for your next project Just make changes to Web.configs
What are the benefits of MVC? Problem: No View State MVC has no View State View state is really helpful for rapid development Not so nice for page size
What are the benefits of MVC? <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY1MzUzMjI0Ng9kFgwCAg8VAXonaHBfbmxhX3RyZWUnLCAnc2l0ZT11cycsICdwYXJ0bmVyPXVzJywgJ2xvZ2dlZGluPUZhbHNlJywgJ2luc3Q9RmFsc2UnLCAncHJvbW9FbGlnaWJsZT1UcnVlJywgJ2xhbmd1YWdlPUVuZ2xpc2gnLCAnaHA9bmxhJ2QCAw8VApQBJ2hwX25sYV9mcmVlJywgJ2hwVGVzdENlbGw9ZGVmYXVsdF9ubGEnLCAnc2l0ZT11cycsICdwYXJ0bmVyPXVzJywgJ2xvZ2dlZGluPUZhbHNlJywgJ2luc3Q9RmFsc2UnLCAncHJvbW9FbGlnaWJsZT1UcnVlJywgJ2xhbmd1YWdlPUVuZ2xpc2gnLCAnaHA9bmxhJ3wnaHBfbmxhX3NlYXJjaCcsICdzaXRlPXVzJywgJ3BhcnRuZXI9dXMnLCAnbG9nZ2VkaW49RmFsc2UnLCAnaW5zdD1GYWx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lc3RyeS5mcmQCGA8VATFodHRwOi8vd3d3LmFuY2VzdHJ5LmNvbS9Ib21lUmVkaXJlY3QuYXNweD9yZWY9MFNFZAIZDxUBFmh0dHA6Ly93d3cuYW5jZXN0cnkuc2VkAhsPFQEMQW5jZXN0cnkuY29tZAIdDxUBFUNvcnBvcmF0ZSBJbmZvcm1hdGlvbmQCHg8VBBB3d3cuYW5jZXN0cnkuY29tDlBSSVZBQ1kgUE9MSUNZEHd3dy5hbmNlc3RyeS5jb20UVGVybXMgYW5kIENvbmRpdGlvbnNkZI5o1QBkDUPswAnGKLEp0SlZ+Rv+" />
Code!Hello World MVC
Code!Contact Form with Validation
Templates – EditorForModel()
Templates
Templates – Customize
Templates – DisplayForModel()
Templates – DisplayForModel()
Templates – Customize
Templates – Customize

More Related Content

What's hot

Future ASP.NET features for UID / HTML developers
Future ASP.NET features for UID / HTML developersFuture ASP.NET features for UID / HTML developers
Future ASP.NET features for UID / HTML developersMark Everard
 
當ZK遇見Front-End
當ZK遇見Front-End當ZK遇見Front-End
當ZK遇見Front-End祁源 朱
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC PresentationVolkan Uzun
 
Introduction to angular js for .net developers
Introduction to angular js  for .net developersIntroduction to angular js  for .net developers
Introduction to angular js for .net developersMohd Manzoor Ahmed
 
Node.js Authentication and Data Security
Node.js Authentication and Data SecurityNode.js Authentication and Data Security
Node.js Authentication and Data SecurityTim Messerschmidt
 
AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application Carlo Bonamico
 
Principles of MVC for PHP Developers
Principles of MVC for PHP DevelopersPrinciples of MVC for PHP Developers
Principles of MVC for PHP DevelopersEdureka!
 
MVC for Desktop Application - Part 3
MVC for Desktop Application - Part 3MVC for Desktop Application - Part 3
MVC for Desktop Application - Part 3晟 沈
 
Angularjs practical project experiences with javascript development in a bank
Angularjs practical project experiences with javascript development in a bankAngularjs practical project experiences with javascript development in a bank
Angularjs practical project experiences with javascript development in a bankDavid Amend
 
MVC for Desktop Application - Part 1
MVC for Desktop Application - Part 1MVC for Desktop Application - Part 1
MVC for Desktop Application - Part 1晟 沈
 
What's new in asp.net mvc 4
What's new in asp.net mvc 4What's new in asp.net mvc 4
What's new in asp.net mvc 4Simone Chiaretta
 
Getting Started with ASP.NET MVC 3 and Razor
Getting Started with ASP.NET MVC 3 and RazorGetting Started with ASP.NET MVC 3 and Razor
Getting Started with ASP.NET MVC 3 and RazorDan Wahlin
 
Learn html and css from scratch
Learn html and css from scratchLearn html and css from scratch
Learn html and css from scratchMohd Manzoor Ahmed
 
WJAX 2012 - Web Apps With AngularJS
WJAX 2012 - Web Apps With AngularJSWJAX 2012 - Web Apps With AngularJS
WJAX 2012 - Web Apps With AngularJSPhilipp Burgmer
 
MVC for Desktop Application - Part 4
MVC for Desktop Application - Part 4MVC for Desktop Application - Part 4
MVC for Desktop Application - Part 4晟 沈
 
learn mvc project in 7 day
learn mvc project in 7 daylearn mvc project in 7 day
learn mvc project in 7 dayQuach Long
 

What's hot (20)

Future ASP.NET features for UID / HTML developers
Future ASP.NET features for UID / HTML developersFuture ASP.NET features for UID / HTML developers
Future ASP.NET features for UID / HTML developers
 
當ZK遇見Front-End
當ZK遇見Front-End當ZK遇見Front-End
當ZK遇見Front-End
 
ASP.NET MVC for Begineers
ASP.NET MVC for BegineersASP.NET MVC for Begineers
ASP.NET MVC for Begineers
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Introduction to angular js for .net developers
Introduction to angular js  for .net developersIntroduction to angular js  for .net developers
Introduction to angular js for .net developers
 
Angularjs Live Project
Angularjs Live ProjectAngularjs Live Project
Angularjs Live Project
 
Node.js Authentication and Data Security
Node.js Authentication and Data SecurityNode.js Authentication and Data Security
Node.js Authentication and Data Security
 
AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application AngularJS Security: defend your Single Page Application
AngularJS Security: defend your Single Page Application
 
Principles of MVC for PHP Developers
Principles of MVC for PHP DevelopersPrinciples of MVC for PHP Developers
Principles of MVC for PHP Developers
 
MVC for Desktop Application - Part 3
MVC for Desktop Application - Part 3MVC for Desktop Application - Part 3
MVC for Desktop Application - Part 3
 
Angularjs practical project experiences with javascript development in a bank
Angularjs practical project experiences with javascript development in a bankAngularjs practical project experiences with javascript development in a bank
Angularjs practical project experiences with javascript development in a bank
 
MVC for Desktop Application - Part 1
MVC for Desktop Application - Part 1MVC for Desktop Application - Part 1
MVC for Desktop Application - Part 1
 
What's new in asp.net mvc 4
What's new in asp.net mvc 4What's new in asp.net mvc 4
What's new in asp.net mvc 4
 
Getting Started with ASP.NET MVC 3 and Razor
Getting Started with ASP.NET MVC 3 and RazorGetting Started with ASP.NET MVC 3 and Razor
Getting Started with ASP.NET MVC 3 and Razor
 
Angular js
Angular jsAngular js
Angular js
 
Learn html and css from scratch
Learn html and css from scratchLearn html and css from scratch
Learn html and css from scratch
 
WJAX 2012 - Web Apps With AngularJS
WJAX 2012 - Web Apps With AngularJSWJAX 2012 - Web Apps With AngularJS
WJAX 2012 - Web Apps With AngularJS
 
MVC for Desktop Application - Part 4
MVC for Desktop Application - Part 4MVC for Desktop Application - Part 4
MVC for Desktop Application - Part 4
 
learn mvc project in 7 day
learn mvc project in 7 daylearn mvc project in 7 day
learn mvc project in 7 day
 
Asp net-mvc-3 tier
Asp net-mvc-3 tierAsp net-mvc-3 tier
Asp net-mvc-3 tier
 

Similar to Introduction to ASP.NET MVC 2

Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Joe Wilson
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentationivpol
 
MVC From Beginner to Advance in Indian Style by - Indiandotnet
MVC From Beginner to Advance in Indian Style by - IndiandotnetMVC From Beginner to Advance in Indian Style by - Indiandotnet
MVC From Beginner to Advance in Indian Style by - IndiandotnetIndiandotnet
 
Introducing the ASP.NET MVC 3
Introducing the ASP.NET MVC 3Introducing the ASP.NET MVC 3
Introducing the ASP.NET MVC 3ldcphuc
 
Technoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development servicesTechnoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development servicesAaron Jacobson
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To MvcVolkan Uzun
 
Modern ASP.NET Webskills
Modern ASP.NET WebskillsModern ASP.NET Webskills
Modern ASP.NET WebskillsCaleb Jenkins
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architectureravindraquicsolv
 
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe
 
Moving from ASP.NET Web Forms to ASP.NET MVC
Moving from ASP.NET Web Forms to ASP.NET MVCMoving from ASP.NET Web Forms to ASP.NET MVC
Moving from ASP.NET Web Forms to ASP.NET MVCkgpainter
 
Top 40 MVC Interview Questions and Answers | Edureka
Top 40 MVC Interview Questions and Answers | EdurekaTop 40 MVC Interview Questions and Answers | Edureka
Top 40 MVC Interview Questions and Answers | EdurekaEdureka!
 
Which is better asp.net mvc vs asp.net
Which is better  asp.net mvc vs asp.netWhich is better  asp.net mvc vs asp.net
Which is better asp.net mvc vs asp.netConcetto Labs
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCMaarten Balliauw
 

Similar to Introduction to ASP.NET MVC 2 (20)

Introduction to ASP.NET MVC
Introduction to ASP.NET MVC Introduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Asp.Net MVC Intro
Asp.Net MVC IntroAsp.Net MVC Intro
Asp.Net MVC Intro
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
MVC From Beginner to Advance in Indian Style by - Indiandotnet
MVC From Beginner to Advance in Indian Style by - IndiandotnetMVC From Beginner to Advance in Indian Style by - Indiandotnet
MVC From Beginner to Advance in Indian Style by - Indiandotnet
 
Introducing the ASP.NET MVC 3
Introducing the ASP.NET MVC 3Introducing the ASP.NET MVC 3
Introducing the ASP.NET MVC 3
 
Technoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development servicesTechnoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development services
 
Introduction To Mvc
Introduction To MvcIntroduction To Mvc
Introduction To Mvc
 
ASP .Net MVC 5
ASP .Net MVC 5ASP .Net MVC 5
ASP .Net MVC 5
 
Modern ASP.NET Webskills
Modern ASP.NET WebskillsModern ASP.NET Webskills
Modern ASP.NET Webskills
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
Aspnet mvc
Aspnet mvcAspnet mvc
Aspnet mvc
 
Mvc Brief Overview
Mvc Brief OverviewMvc Brief Overview
Mvc Brief Overview
 
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
SoftServe - "ASP.NET MVC як наступний крок у розвитку технології розробки Web...
 
A4 from rad to mvc
A4 from rad to mvcA4 from rad to mvc
A4 from rad to mvc
 
Moving from ASP.NET Web Forms to ASP.NET MVC
Moving from ASP.NET Web Forms to ASP.NET MVCMoving from ASP.NET Web Forms to ASP.NET MVC
Moving from ASP.NET Web Forms to ASP.NET MVC
 
Top 40 MVC Interview Questions and Answers | Edureka
Top 40 MVC Interview Questions and Answers | EdurekaTop 40 MVC Interview Questions and Answers | Edureka
Top 40 MVC Interview Questions and Answers | Edureka
 
Mvc
MvcMvc
Mvc
 
Which is better asp.net mvc vs asp.net
Which is better  asp.net mvc vs asp.netWhich is better  asp.net mvc vs asp.net
Which is better asp.net mvc vs asp.net
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 

More from Joe Wilson

Adding a timeline to your web app
Adding a timeline to your web appAdding a timeline to your web app
Adding a timeline to your web appJoe Wilson
 
Boulder Tech Throwdown - Rails vs .NET
Boulder Tech Throwdown - Rails vs .NETBoulder Tech Throwdown - Rails vs .NET
Boulder Tech Throwdown - Rails vs .NETJoe Wilson
 
MVC Views In Depth
MVC Views In DepthMVC Views In Depth
MVC Views In DepthJoe Wilson
 
Whats New In Mvc 2
Whats New In Mvc 2Whats New In Mvc 2
Whats New In Mvc 2Joe Wilson
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And MockingJoe Wilson
 
Intermediate ASP.NET MVC
Intermediate ASP.NET MVCIntermediate ASP.NET MVC
Intermediate ASP.NET MVCJoe Wilson
 

More from Joe Wilson (6)

Adding a timeline to your web app
Adding a timeline to your web appAdding a timeline to your web app
Adding a timeline to your web app
 
Boulder Tech Throwdown - Rails vs .NET
Boulder Tech Throwdown - Rails vs .NETBoulder Tech Throwdown - Rails vs .NET
Boulder Tech Throwdown - Rails vs .NET
 
MVC Views In Depth
MVC Views In DepthMVC Views In Depth
MVC Views In Depth
 
Whats New In Mvc 2
Whats New In Mvc 2Whats New In Mvc 2
Whats New In Mvc 2
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
Intermediate ASP.NET MVC
Intermediate ASP.NET MVCIntermediate ASP.NET MVC
Intermediate ASP.NET MVC
 

Introduction to ASP.NET MVC 2

  • 1. Introduction to ASP.NET MVC 2 Joe Wilson Volare Systems, Inc. Email: joe@volaresystems.com Blog: http://VolareSystems.com/Blog Twitter: joe_in_denver
  • 2. Agenda What is MVC? What are the benefits of MVC? Code walkthroughs Drawbacks of MVC Future of MVC Resources
  • 3. Quick Audience Poll Who has used Web Forms and not MVC? Who has used MVC?
  • 4. Where does MVC fit? Web Forms MVC ASP.NET (Request, Response, Session, Cookies, QueryString, Master Pages)
  • 5. What is MVC? M= Model V= View C= Controller
  • 6. What is MVC? – Views Are .ASPX and .ASCX files Inherit from ViewPage Holds user interface elements (HTML, CSS, JavaScript) Views should not contain much logic Simple “if”s or “foreach”es are OK
  • 7. What is MVC? – Controllers Are .CS files Inherit from Controller Code is in Actions (methods) Validate user input before moving on Works with Models for small logic and data access Render Views, JSON, XML, File, etc.
  • 8. What is MVC? – Models Are .CS files and just POCOs MVC doesn’t dictate how to set up Models Data to display in the View or post from the View back to the Controller Good place for validation attributes Good place for light, display-related logic (FullName, Totals, IsUserLoggedIn, etc.)
  • 9. What about a bigger MVC project? http://whocanhelpme.codeplex.com
  • 10. How Web Forms Works Event Based OnPreRender, OnLoad Page http://server/ProductEdit.aspx Request Response HTML, JSON, File, XML
  • 11. How MVC Works Route Based Controller/Action Action Controller http://server/product/edit Request Response HTML, JSON, File, XML
  • 12. How MVC Works Request (GET or POST) Routing Engine Controller (Action) Response View, JSON, File, XML Model
  • 13. MVC Conventions Action Controller http://server/product/edit View Folder
  • 14. What are the benefits of MVC? Benefit: Separation of Concerns guidance MVC gives guidance about what kind of code goes where Convention over configuration Don’t dump all your code in Page_Load and Button_Click
  • 15. What are the benefits of MVC? Style Sheets, Images Controllers Models JavaScript Views Master Pages Tests
  • 16. What are the benefits of MVC? Benefit: Testability MVC allows creation of a new Controller inside a test Web Forms code behind files are hard to test because HttpContext is hard to mock
  • 17. What are the benefits of MVC? Benefit: Clean HTML MVC controls keep their IDs Easier to navigate with JavaScript and jQuery Easier to build XHTML and Section 508 compliant sites (use W3C Validators and Section508.info to check)
  • 18. What are the benefits of MVC? HTML from Web Forms <span id="ctl00_MainContent_uxdPHAllContent_TripSelector_lblFromDate"> From Date:</span> <input type="text" name="ctl00$MainContent$uxdPHAllContent$TripSelector$txtFromDate" id="ctl00_MainContent_uxdPHAllContent_TripSelector_txtFromDate" /> HTML from MVC <label for="FromDate">From Date:</label> <input type="text"name="FromDate"id="FromDate" />
  • 19. What are the benefits of MVC? Benefit: Clean URLs MVC has more hackable, SEO-friendly URLs URLs without query strings
  • 20. What are the benefits of MVC? URLs for ASP.NET Web Forms http://mysite.com/Shop.aspx?Category=Shirts http://mysite.com/Shop.aspx?ID=123 URLs for ASP.NET MVC http://mysite.com/Shop/Category/Shirts http://mysite.com/Shop/ID/123
  • 21.
  • 22.
  • 23. What are the benefits of MVC? Benefit: Can run alongside Web Forms Don’t have to wait for your next project Just make changes to Web.configs
  • 24. What are the benefits of MVC? Problem: No View State MVC has no View State View state is really helpful for rapid development Not so nice for page size
  • 25. What are the benefits of MVC? <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY1MzUzMjI0Ng9kFgwCAg8VAXonaHBfbmxhX3RyZWUnLCAnc2l0ZT11cycsICdwYXJ0bmVyPXVzJywgJ2xvZ2dlZGluPUZhbHNlJywgJ2luc3Q9RmFsc2UnLCAncHJvbW9FbGlnaWJsZT1UcnVlJywgJ2xhbmd1YWdlPUVuZ2xpc2gnLCAnaHA9bmxhJ2QCAw8VApQBJ2hwX25sYV9mcmVlJywgJ2hwVGVzdENlbGw9ZGVmYXVsdF9ubGEnLCAnc2l0ZT11cycsICdwYXJ0bmVyPXVzJywgJ2xvZ2dlZGluPUZhbHNlJywgJ2luc3Q9RmFsc2UnLCAncHJvbW9FbGlnaWJsZT1UcnVlJywgJ2xhbmd1YWdlPUVuZ2xpc2gnLCAnaHA9bmxhJ3wnaHBfbmxhX3NlYXJjaCcsICdzaXRlPXVzJywgJ3BhcnRuZXI9dXMnLCAnbG9nZ2VkaW49RmFsc2UnLCAnaW5zdD1GYWxzZScsICdwcm9tb0VsaWdpYmxlPVRydWUnLCAnbGFuZ3VhZ2U9RW5nbGlzaCcsICdocD1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QuYXNweD9yZWY9MFNFZAIZDxUBFmh0dHA6Ly93d3cuYW5jZXN0cnkuc2VkAhsPFQEMQW5jZXN0cnkuY29tZAIdDxUBFUNvcnBvcmF0ZSBJbmZvcm1hdGlvbmQCHg8VBBB3d3cuYW5jZXN0cnkuY29tDlBSSVZBQ1kgUE9MSUNZEHd3dy5hbmNlc3RyeS5jb20UVGVybXMgYW5kIENvbmRpdGlvbnNkZI5o1QBkDUPswAnGKLEp0SlZ+Rv+" />
  • 37. Recap - Key Benefits of MVC Simple web framework Separation of Concerns Convention over configuration Easier testing Model Binding Validation in the model Templates
  • 38.
  • 39. Chart => Google Charts or a jQuery plugin
  • 40.
  • 41. Drawbacks of MVC No more OnClick server events for buttons, etc. Different enough to have a learning curve Ideas for better View engines still solidifying (Web Forms, Spark, NHaml, Razor, etc.)
  • 42. Future of MVC (MVC 3, Preview 1) New Razor view engine .CSHTML files Uses @ to escape to C# instead of <% %>
  • 43. Future of MVC (MVC 3, Preview 1) Support for multiple view engines (Spark, Razor, Web Forms, NHaml, etc.) Common Service Locator for dependency resolution Global action filters (error handling, authorization)
  • 44. Resources Learning ASP.NET MVC ASP.NET MVC official site - http://www.asp.net/mvc Community Four MVC - http://www.c4mvc.net Keeping up with changes to ASP.NET MVC Phil Haack’s Blog - http://haacked.com Scott Guthrie’s Blog - http://weblogs.asp.net/scottgu Advanced ASP.NET MVC Sharp Architecture - http://sharparchitecture.net Who Can Help Me? - http://whocanhelpme.codeplex.com Eric Hexter’s Blog - http://lostechies.com/blogs/hex Jimmy Bogard’s Blog - http://lostechies.com/blogs/jimmy_bogard Email: joe@volaresystems.com Blog: http://VolareSystems.com/Blog Twitter: joe_in_denver