Upload
lanvige-jiang
View
6.573
Download
2
Embed Size (px)
DESCRIPTION
Head first asp.net mvc 2.0
Citation preview
Head First ASP.Net MVC 2.0
Zhiming JiangMSN GMD Integration
TOPIC
• Review• Getting started with ASP.NET MVC• Understanding ASP.NET MVC• Customizing and Extending• Best Practices• MVC 2.0 New Features
REVIEWThe way of ASP.NET MVC
The Downside of ASP.NET
• Very complex page pipeline engine• Difficult to maintain • Impossible to test
– Difficulty partially arises from simulating Context, Request, Response, and Session objects.
• The cryptic control ids and sensitivities of ViewState
• Overly mix business and presentation logic• Event-driven model
Innovation!
Based on Python
1970S
2003 RoR
{ ASP.NET MVC }2009.3 MVC1
2010.4 MVC2
MVC FrameworkHistory
….
ASP.NET MVC IS……
• New ASP.NET application development style– Another is“ASP.NET Web Form”– Fill the gaps of ASP.NET Web Form
• New choice• Full control over URLs• Full control over HTML• Easier to test (TDD) • Flexible, extendable, easily replaced
ASP.NET MVC IS NOT……
• The substitute of 3-tier structure• ASP.NET Web Form’s substitute • ASP.NET Web Form promotion version– ASP.NET Web Form 4.0
• Fit RAD• Fit every project• Fit everyone
Different Between with Web Form
Classic Web Form ASP.NET MVC
Postback REST, HTML Post
Code behind Separate controller
Single form Multiple forms
Server controls HTML Helpers
Page and control lifecycle Controller
GETTING STARTED WITH ASP.NET MVC
ASP.NET MVC 101
ASP.NET MVC Framework Structure
ASP.NET Routing(System.Web.Routing.dll)
ASP.NET Abstractions(System.Web.Abstractions.dll)
ASP.NET MVC(System.Web.Mvc.dll)
But what is the work process?但是具体的流程是什么样?
Classic Application Architecture
MvcDemo.Web.UI
MvcD
emo.M
odels
MvcDemo.Web.Controllers
MvcDemo.Business
Presentation
BizService
MvcDemo.DataDataAccessResponsity
ASP.NET MVC Excute Process
UNDERSTANDING ASP.NET MVCUnderstanding Models, Views, and Controllers
ASP.NET Routing
• URL Patterns• Setting Default Values for URL Parameters• Adding Constraints to Routes• Scenarios When Routing Is Not Applied• How URLs Are Matched to Routes• Accessing URL Parameters in a Routed Page• ASP.NET Routing and Security• ASP.NET Routing versus URL Rewriting
Working with Models
• What’s Model
• Validation
Controllers & Action
• Receiving input– QueryString, Request.Form, FormCollection, Custome(IModelBinding)
• Filter• Aysnc action• Producing output
– Action Result, View Data, View Model
• How defines– End with the word Controller– Inherit from System.Web.Mvc.Controller (or implement Icontroller– Contain public methods that return ActionResult
Filtering Action Methods
Working with Views
• View Engine• View Page• View Data• View Helper• Form Post• Using MasterPage• Order
CUSTOMIZING AND EXTENDINGMVC Custom and Extensions
Customizing & Extending
• Extending URL Routing• Customer ControllerFactory• Extending Controller & Action• Custom View Engine• T4 Template
BEST PRACTICESTruth in Practice
Best Practices
Securing MVC applications Dependency Injection of Controllers Using RESTful Architecture Handling errors in MVC applications Unit Test & MVC Mock Helpers Using AJAX in ASP.NET MVC applications Improving ASP.NET MVC application performance Localizing ASP.NET MVC Validation Deploying MVC applications
MVC 2.0 NEW FEATURESAreas, Async Controllers Support, Scaffold …
• New Strongly Typed HTML Helpers• Enhanced Model Validation support across both
server and client• Auto-Scaffold UI Helpers with Template
Customization• Support for splitting up large applications into
“Areas”• Asynchronous Controllers support that enables
long running tasks in parallel• Support for rendering sub-sections of a page/site
using Html.RenderAction• Lots of new helper functions, utilities, and API
enhancements• Improved Visual Studio tooling support
Areas
• Introduction– Organizing our projects hierarchically into
folders and namespaces
• Building a portable area• Embedding Views• Distributing a portable area
Async Controllers Support
• Change the way of request handling• Decide whether the action is async or
not• Execute an action• ModelBinder support• Limitations and drawbacks
RECOURSENice projects to learn MVC
Oxite 2: An official CMS ProductMvcContrib: a Codeplex Foundation Projecthttp://mvccontrib.codeplex.com/http://tailspintravel.codeplex.comhttp://mvcsitemap.codeplex.com/http://mvcmembership.codeplex.com/http://code.msdn.microsoft.com/aspnetmvcsamples
http://nerddinner.codeplex.com/[Video]Creating NerdDinner.com with MVC
IT IS OVER, THANKSYour Feedback is Important!
Please fill out the session evaluation form provided and drop it off with the staff at the exit.