Ori Calvo, 2010
“If people want to have maximum reach across *all* devices then HTML will provide the broadest reach” Scott Guthrie, Corporate Vice President, MicrosoftCorporate Vice President
Objectives Why MVC? ASP.NET MVC In Detail Better Integration Conclusions
Prerequisites ASP.NET Developer Good understanding of HTML and HTTP Good understanding of C# 3.0 Language No MVC Experience is required
Quick Demo Create new MVC Project Create new controller Create new View
Web Development Today Browsing experience everywhere Greater variety of devices and browsers Increasing drive for web standards HTML5 CSS3 Multidiscipline Web Server HTML Generation Data Services Service Orientation
Web Development Today Rich Client Side Experience Did we say HTML5? Easy integration with client side libraries Agile Test Driven Development REST over SOAP Clean URLs Ruby on Rails Year 2004 MVC based Built-in ORM tool
Classical ASP.NET Huge shift at that time Object oriented approach Compiled web pages Stateful UI Event Driven Drag and Drop Designer Windows Forms Developing Experience Is here to stay !!!
What’s wrong with it? Is “Windows Forms” approach suited? Limited control over HTML Encourages mixing of presentation and logic Hard to test ViewState Complex page life cycle Hard to integrate with other libraries
ASP.NET MVC Separation of concerns Built on top of ASP.NET platform Tight control over HTML Designed to be testable Extensible routing system Better integration with 3 rd party libraries Open source Language innovations
Web Platform Installer
MVC Ingredients Routing System Controller Action Filter View Model Model State View Data
Demo Introduction to PhoneBook BL Add GroupController Pass model object to view Add Group.Index View Configure Routing Support clicking Outgoing URL Use ViewData
Routing System Makes your URLs clean and human friendly No correspondence between files and URLs Inbound URL Outgoing URL Implemented by System.Web.Routing.dll Originally shipped with.NET 3.5 SP1 You can use it in your classical ASP.NET 4.0 web pages Was merged into System.Web.dll (starting 4.0)
Controller The controller is the boss Responsible for application logic Receiving user input Work against the domain model Moving the user between different UI Implements IController Single method: Execute Usually derives from Controller
Controller Base Class Action Action result Filters [OutputCache(Duration=600, VaryByParam”*”)] public class DemoController : Controller { public ViewResult ShowGreeting() { return View(“MyView”);}
Controller – Producing Output Types of action results View PartialView Redirect Json JavaScript File Content Others
Demo Submitting data to the controller Use action filters (GET, POST) Model Binding Validation
Controller - Receiving Input Use context objects HttpContext RouteData TempData Implicit model binding Through action parameters Easier to test Explicit model binding Full control
Model Binding Is built from Form RouteData QueryString The DefaultModelBinder Converts strings into.NET objects Uses.NET “Type Converter” facility
Demo Add Master Page Add Partial View
Demo Add Authentication filter Implement custom filter Register global filter
Action Filter Attach reusable behavior Logging Authorization Caching Inject extra logic Great from testing perspective Action filter implements IActionFilter Result filter implements IResultFilter ActionFilterAttribute implements both
Demo – Entity Framework Generate model from DB Implement BL interfaces
Demo - jQuery Unobtrusive JavaScript Partial Refresh Working with JSON Client side templates jQuery UI
Demo - Testing Add test project IoC pattern ControllerBuilder
Questions ?
Conclusions A different way to develop web applications Hopefully, better “Semi” WOW effect Long term benefits Feel natural No rich server control library Be ready to integrate other libraries You must know HTTP and HTML good What about client side MVC?
Read more MVC 3.0 RC is released today !!!
Thank You !!!