www.dev-one.com
Fabian Vilers
Twitter: @fvilers
Hands onASP.NET MVC
Dev One is your dedicated partner
providing high quality experts on
architecture, development, and
testing roles on IT projects using
Microsoft .NET technologies.
Visit us on:
http://www.dev-one.com
We will help your enterprise to build a state
of the ar t solution using the latest available
technologies so you can rapidly deploy your
applications and ser vices.
Our proven experience, and a deep
understanding of your business, will help us
to you reduce your IT development costs
and let your employees concentrate on your
core business.
We are aimed at providing consultancy
exper ts on architecture, development, and
testing roles, especially using the .NET
technologies and the Microsoft ecosystem.
With more than 10 years of multiple IT
development experiences, we have forged a
set of skills through various project &
missions in several activity sectors that
enables us to deliver you high quality
ser vices.
ABOUT DEV ONE
ASP.NET MVC – Hands on 2
 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 3
AGENDA
4ASP.NET MVC – Hands on
PRESENTATION
 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 5
WHAT IS MVC?
 Ruby on Rails
 Django and Python
 Spring, Struts and Java
 Zend Framework and PHP
 MonoRail
 …
ASP.NET MVC – Hands on 6
MVC ON THE WEB TODAY
 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 7
ASP.NET MVC
ASP.NET MVC – Hands on 8
TIMELINE
• ScottGu sketched
out the core of
ASP.NET MVC
(~100 lines of
code)
February 2007
• Presenstation of
Scalene at the
Austin ALT.NET
conference
September
2007 • First Community
Technology
Preview
December 2007
• ASP.NET MVC 1.0
March 2009
• ASP.NET MVC
source code was
released under
the MS-PL
April 2009
• ASP.NET MVC 2.0
• Shipped with
Visual Studio 2010
March 2010
• ASP.NET MVC 3.0
• Shipped with
Visual Studio 2010
January 2011
9ASP.NET MVC – Hands on
COMPARISON WITH
ASP.NET WEB FORMS
 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 10
WHAT WEB FORMS DOES WELL
 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 11
WHERE WEB FORMS DOESN’T FIT
 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 12
ASP.NET MVC BELIEVES
 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
SHOULD YOU FEAR ASP.NET MVC?
ASP.NET MVC – Hands on 13
14ASP.NET MVC – Hands on
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 15
THE MVC PATTERN
 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 16
MODEL
 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 17
VIEW
 Handle user interaction
 Query the model
 Select the right view to render
ASP.NET MVC – Hands on 18
CONTROLLER
19ASP.NET MVC – Hands on
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 20
WHAT’S NEW IN ASP.NET MVC 3
21ASP.NET MVC – Hands on
DEMOS
 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 22
BOOK STORE
23ASP.NET MVC – Hands on
Q & A
ASP.NET MVC – Hands on 24

Asp.netmvc handson

  • 1.
  • 2.
    Dev One isyour dedicated partner providing high quality experts on architecture, development, and testing roles on IT projects using Microsoft .NET technologies. Visit us on: http://www.dev-one.com We will help your enterprise to build a state of the ar t solution using the latest available technologies so you can rapidly deploy your applications and ser vices. Our proven experience, and a deep understanding of your business, will help us to you reduce your IT development costs and let your employees concentrate on your core business. We are aimed at providing consultancy exper ts on architecture, development, and testing roles, especially using the .NET technologies and the Microsoft ecosystem. With more than 10 years of multiple IT development experiences, we have forged a set of skills through various project & missions in several activity sectors that enables us to deliver you high quality ser vices. ABOUT DEV ONE ASP.NET MVC – Hands on 2
  • 3.
     Presentation  Whatis 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 3 AGENDA
  • 4.
    4ASP.NET MVC –Hands on PRESENTATION
  • 5.
     The MVCpattern 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 5 WHAT IS MVC?
  • 6.
     Ruby onRails  Django and Python  Spring, Struts and Java  Zend Framework and PHP  MonoRail  … ASP.NET MVC – Hands on 6 MVC ON THE WEB TODAY
  • 7.
     Separation ofapplication 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 7 ASP.NET MVC
  • 8.
    ASP.NET MVC –Hands on 8 TIMELINE • ScottGu sketched out the core of ASP.NET MVC (~100 lines of code) February 2007 • Presenstation of Scalene at the Austin ALT.NET conference September 2007 • First Community Technology Preview December 2007 • ASP.NET MVC 1.0 March 2009 • ASP.NET MVC source code was released under the MS-PL April 2009 • ASP.NET MVC 2.0 • Shipped with Visual Studio 2010 March 2010 • ASP.NET MVC 3.0 • Shipped with Visual Studio 2010 January 2011
  • 9.
    9ASP.NET MVC –Hands on COMPARISON WITH ASP.NET WEB FORMS
  • 10.
     Represent aPage 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 10 WHAT WEB FORMS DOES WELL
  • 11.
     ViewState ispowerful, 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 11 WHERE WEB FORMS DOESN’T FIT
  • 12.
     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 12 ASP.NET MVC BELIEVES
  • 13.
     ASP.NET MVCis 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 SHOULD YOU FEAR ASP.NET MVC? ASP.NET MVC – Hands on 13
  • 14.
    14ASP.NET MVC –Hands on THE MVC PATTERN
  • 15.
     Model  objectsare 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 15 THE MVC PATTERN
  • 16.
     Business logicand 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 16 MODEL
  • 17.
     Application’s userinterface 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 17 VIEW
  • 18.
     Handle userinteraction  Query the model  Select the right view to render ASP.NET MVC – Hands on 18 CONTROLLER
  • 19.
    19ASP.NET MVC –Hands on WHAT’S NEW IN ASP.NET MVC 3
  • 20.
     Razor ViewEngine  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 20 WHAT’S NEW IN ASP.NET MVC 3
  • 21.
    21ASP.NET MVC –Hands on DEMOS
  • 22.
     Using theASP.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 22 BOOK STORE
  • 23.
    23ASP.NET MVC –Hands on Q & A
  • 24.
    ASP.NET MVC –Hands on 24