Está en la página 1de 23

ASP.

NET MVC Hands on


Agenda

 Presentation
 What is MVC?
 MVC on the web today
 ASP.NET MVC
 Timeline
 Comparison with ASP.NET web forms
 What web forms does well
 Where web forms doesn’t fit
 ASP.NET MVC believes
 Should you fear ASP.NET MVC?
 The MVC pattern
 Model
 View
 Controller
 What’s new in ASP.NET MVC 3
 Demos
 Q&A

ASP.NET MVC – Hands on


2
Presentation

3
What is MVC?

 The MVC pattern is 30+ years old!


 It is a powerful and elegant means of separating concerns
 It makes it easier to test application
 It promotes parallel development thanks to the loose coupling
between the three main components

ASP.NET MVC – Hands on


4
MVC on the web today

 Ruby on Rails
 Django and Python
 Spring, Struts and Java
 Zend Framework and PHP
 MonoRail
 …

ASP.NET MVC – Hands on


5
ASP.NET MVC

 Separation of application tasks (input logic, business logic, and UI


logic), testability, and test-driven development (TDD) by default
 An extensible and pluggable framework
 A powerful URL-mapping component that lets you build applications
that have comprehensible and searchable URLs
 Convention over configuration
 Don’t repeat yourself, keep it simple (DRY/KISS principles)

ASP.NET MVC – Hands on


6
Timeline

September
March 2009 March 2010
• ScottGu sketched 2007 • First Community • ASP.NET MVC • ASP.NET MVC 3.0
out the core of Technology source code was • Shipped with
ASP.NET MVC • Presenstation of Preview • ASP.NET MVC 1.0 released under the • ASP.NET MVC 2.0
Visual Studio
(~100 lines of Scalene at the MS-PL • Shipped with 2010
code) Austin ALT.NET Visual Studio
conference 2010
February 2007 December 2007 April 2009 January 2011

ASP.NET MVC – Hands on


77
Comparison with
ASP.NET web forms

8
What web forms does well

 Represent a Page as control tree


 Give these server-side controls events like their desktop counterparts
 Hide as much HTTP and HTML as is reasonable
 Make state management as transparent as possible

ASP.NET MVC – Hands on


9
Where web forms doesn’t fit

 ViewState is powerful, but it has its drawbacks (weight,…)


 Page life cycle can be a nightmare
 Limited control over HTML
 Client IDs and the ctl00$ContentPlaceHolder1$UserControl1$TextBox1 syndrome
 It’s nearly impossible to run a Web Form through its life cycle outside
IIS

ASP.NET MVC – Hands on


10
ASP.NET MVC believes

 Guiding tenets:
 Be extensible, maintainable, and flexible
 Be testable
 Get out of the user’s way when necessary
 Serving methods, not files
 Separation of concerns
 ScottHa said: « ASP.NET MVC is Web Forms unplugged »

ASP.NET MVC – Hands on


11
Should you fear ASP.NET MVC?

 ASP.NET MVC is built on top of ASP.NET


 ASP.NET MVC is not a replacement for anything
 It is just an alternative
 It’s a totally different approach

ASP.NET MVC – Hands on


12
The MVC pattern

13
The MVC pattern

 Model
 objects are the parts of the
application that implement the
logic for the application’s data
domain
 View
 components that display the
application’s user interface
 Controller
 components that handle user
interaction, work with the model,
and ultimately select a view to
render

ASP.NET MVC – Hands on


14
Model

 Business logic and validation of the application’s data domain


 Totally independant from the views or the controllers
 Model state can be stored in memory, database, XML files,…

ASP.NET MVC – Hands on 15


15
View

 Application’s user interface using data from the model


 No interaction with the models or the controllers
 Views can be strongly typed
 Almost no code

ASP.NET MVC – Hands on


16
Controller

 Handle user interaction


 Query the model
 Select the right view to render

ASP.NET MVC – Hands on


17
What’s new in ASP.NET
MVC 3

18
What’s new in ASP.NET MVC 3

 Razor View Engine


 Support for multiple view engine
 Global action filters
 « ViewBag » property
 New « ActionResult » types
 JavaScript and AJAX improvements
 Client-side validation enabled by default
 Remote validator
 JSON binding support
 Data annotations metadata attributes
 Validation interfaces
 Dependency injection improvements
 Partial-Page Output Caching
 Granular Control over Request Validation
 …

ASP.NET MVC – Hands on


19
Demos

20
Book store

Using the ASP.NET MVC 3 template and playing around with Razor
First data access and display a list of authors
Manage authors
Display a list of books
Create and edit a book using the ViewModel pattern

Source code available on: http://vil.rs/qK3rMG

ASP.NET MVC – Hands on


21
Q&A

22
23

También podría gustarte