aspnet mvc

30
Head First ASP.Net MVC 2.0 Zhiming Jiang MSN GMD Integration

Upload: hiep-luong

Post on 17-Nov-2014

2.559 views

Category:

Technology


2 download

DESCRIPTION

ASP.NET MVC

TRANSCRIPT

Page 1: Aspnet mvc

Head First ASP.Net MVC 2.0

Zhiming JiangMSN GMD Integration

Page 2: Aspnet mvc

TOPIC

• Review• Getting started with ASP.NET MVC• Understanding ASP.NET MVC• Customizing and Extending• Best Practices• MVC 2.0 New Features

Page 3: Aspnet mvc

REVIEWThe way of ASP.NET MVC

Page 4: Aspnet 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

Page 5: Aspnet mvc

Innovation!

Page 6: Aspnet mvc

Based on Python

1970S

2003 RoR

{ ASP.NET MVC }2009.3 MVC1

2010.4 MVC2

MVC FrameworkHistory

….

Page 7: Aspnet mvc

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

Page 8: Aspnet mvc

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

Page 9: Aspnet mvc

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

Page 10: Aspnet mvc

GETTING STARTED WITH ASP.NET MVC

ASP.NET MVC 101

Page 11: Aspnet mvc

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)

Page 12: Aspnet mvc

But what is the work process?但是具体的流程是什么样?

Page 13: Aspnet mvc

Classic Application Architecture

MvcDemo.Web.UI

MvcD

emo.M

odels

MvcDemo.Web.Controllers

MvcDemo.Business

Presentation

BizService

MvcDemo.DataDataAccessResponsity

Page 14: Aspnet mvc

ASP.NET MVC Excute Process

Page 15: Aspnet mvc

UNDERSTANDING ASP.NET MVCUnderstanding Models, Views, and Controllers

Page 16: Aspnet mvc

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

Page 17: Aspnet mvc

Working with Models

• What’s Model

• Validation

Page 18: Aspnet mvc

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

Page 19: Aspnet mvc

Filtering Action Methods

Page 20: Aspnet mvc

Working with Views

• View Engine• View Page• View Data• View Helper• Form Post• Using MasterPage• Order

Page 21: Aspnet mvc

CUSTOMIZING AND EXTENDINGMVC Custom and Extensions

Page 22: Aspnet mvc

Customizing & Extending

• Extending URL Routing• Customer ControllerFactory• Extending Controller & Action• Custom View Engine• T4 Template

Page 23: Aspnet mvc

BEST PRACTICESTruth in Practice

Page 24: Aspnet mvc

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

Page 25: Aspnet mvc

MVC 2.0 NEW FEATURESAreas, Async Controllers Support, Scaffold …

Page 26: Aspnet mvc

• 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

Page 27: Aspnet mvc

Areas

• Introduction– Organizing our projects hierarchically into

folders and namespaces

• Building a portable area• Embedding Views• Distributing a portable area

Page 28: Aspnet mvc

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

Page 29: Aspnet mvc

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

Page 30: Aspnet 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.