3. devcoach.com
What is new?
• HTML 5
– A few tags
– … Less Markup
• CSS 3
– Rounded corners
– Drop shadow?
– Media Queries
– … Less Definition
• EcmaScript 5
– Web Sockets
– Server Sent Events
– … Less Code
5. devcoach.com
What is there
• Maintain Clean Separation of Concerns
• Extensible and Pluggable
• Enable clean URLs and HTML
• Build on to of a mature platform
6. devcoach.com
Whats the difference to Web Forms
• File System Based
• Event based Server Forms
– Makes adoption easy for e.g. VB forms devs.
– Process logic is coupled with page life-cycle.
• Difficult to test using automated tests.
• Server Controls
– Easy because they render the HTML for you.
– Often not so nice because they render it the way
they want.
8. devcoach.com
What Do They Have In Common?
• Visual Studio web designer
• Master pages
• Membership/Roles/Profile providers
• Globalization
• Caching
9. devcoach.com
The MVC Pattern
• The request hits the controller
• Loads the model
• Returns the view to return to the client
Controller
Model
View
11. devcoach.com
First of all think of the URLs
• It's in the nature of the pattern that it makes
you think before you code!
12. devcoach.com
Nice URLs
• REST-like
• Fits with the nature of the web
– MVC exposes the stateless nature of HTTP
• Friendlier to humans
• Friendlier to web crawlers
– Search engine optimization (SEO)
15. devcoach.com
Controllers
• Base Controller Class
– Basic Functionality most folks will use
• IController Interface
– Ultimate Control for the Control Freak
• IControllerFactory
– For plugging in your own stuff (IOC, etc)
21. devcoach.com
Action Filters
• Allow code to be wrapped around controller
actions and view results
• Similar to HttpModules
• Provide a mechanism for removing cross
cutting code (logging, authorization, etc.)
from controller classes
22. devcoach.com
Action Filters
public class MyFilter
: ActionFilterAttribute
{
public override void OnActionExecuting(
ActionExecutingContext filterContext)
{
// Your code here…
}
}
29. devcoach.com
Views
• Pre-defined and extensible rendering
helpers
– Can use .ASPX, .ASCX, .MASTER, etc.
– Can replace with other view technologies:
• Template engines (NVelocity, Brail, …).
• Output formats (images, RSS, JSON, …).
• Mock out for testing.
– Controller sets data on the View
• Loosely typed or strongly typed data
33. devcoach.com
View Engine
• 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 to write
– Generate totally different mime/types
• Images
• RSS, JSON, XML, OFX, etc.
• VCards, whatever.
39. devcoach.com
Assign Template
• By Type:
DateTime.ascx
• By Name:
Html.DisplayForModel(“MyTemplate.ascx”);
• By UIHint
[UIHint("MyPropertyTemplate")]
public string Title { get; set; }
[HiddenInput]