everything starts so simple, but then…

29
Microsoft ASP.NET MVC 2: The New Stuff Stephen Walther Senior Program Manager Microsoft Corporation PDC09-FT22

Upload: jesse-maxwell

Post on 26-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Microsoft ASP.NET MVC 2: The New Stuff

Stephen WaltherSenior Program ManagerMicrosoft Corporation

PDC09-FT22

ASP.NET MVC 1.0

Everything starts so simple, but then…

ASP.NET MVC 1.0

ASP.NET MVC 1.0

Enables you to build applications that can be maintained over the long term:

> Supports a clear separation of concerns

> Supports testability

> Supports “close to the metal” programming experience

What’s New in MVC 2?

> Better Separation of Concerns (Maintainability)> Html.RenderAction()> Areas

> Easier Validation (Maintainability/Productivity)> Data Annotations> Client Validation

> Helper Improvements (Maintainability/Productivity)> Strongly-Typed Helpers> Templated Helpers

ASP.NET MVC 2

Visual Studio 2010Included

Visual Studio 2008 (Service Pack 1)Download

Both versions built against .NET 3.5

RenderAction (Composability)

<% Html.RenderAction() %>

> Menus> Banner Ads> Shopping Carts

Any UI that appears in multiple pages and requires business logic

RenderAction (Maintainability)

> Html.RenderPartial()Renders UI

> Html.RenderAction()Invokes controller action that renders UI

Using RenderAction

demo

Areas (Maintainability)

AreasEnables you to maintain a clear separation of functionality in a single project

AreaRegistration.RegisterAllAreas();

Using Areas

demo

Validation (Maintainability/Productivity)

Client-Side Validation

Server-Side Validation

Model Class

Define Validation

Validation (Maintainability/Productivity)> Model Validation Providers

> Data Annotation (Default)> Enterprise Library> XML

Anything you want

Validation (Maintainability/Productivity)Data Annotation Validators

> [Required]> [Range]> [RegularExpression]> [StringLength]Custom Validator

Validation (Maintainability/Productivity)

public class Customer{ [Required] [DisplayName("First Name")] public string FirstName { get; set; }

[Required] [RegularExpression(@"\S+@\S+\.\S+")] public string Email { get; set; }}

Server-Side Validation with Data Annotations

demo

Validation (Maintainability/Productivity)Client-Side Validation

<script src="../../Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>

<script src="../../Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>

<% Html.EnableClientValidation(); %>

Client-Side Validation

demo

Strongly-Typed Helpers (Maintainability)> Html.TextBoxFor()> Html.TextAreaFor()> Html.ValidationMessageFor()…

Templated Helpers (Productivity)

Display Helper Methods> Html.Display()> Html.DisplayFor()> Html.DisplayForModel()

Edit Helper Methods> Html.Editor()> Html.EditorFor()> Html.EditorForModel()

Templated Helpers (Productivity)

Specify Template:> By Type:

DateTime.ascx

> By Name:Html.DisplayForModel(“MyTemplate.ascx”);

> By UIHint[UIHint("MyPropertyTemplate")]public string Title { get; set; }

Templated Helpers (Productivity)

Fallback:> Employee> Person> Object

Templated Helpers

demo

Other New Features

> Security> HTML Encoding Syntax

> <%: Model.NewPostByEvilPerson %> > Works with ASP.NET 4> JsonResult

> Performance Improvements> Asynchronous Controller Actions

> Convenience Improvements> Default Parameters for Controller Actions> HttpPost, HttpGet, RequiresHttps

> Value Providers

Value Providers

Source for Model Binder data:

> FormValueProvider> RouteDataValueProvider> QueryStringValueProvider> HttpFileCollectionValueProvider

and custom…

Using a JsonValueProvider with ASP.NET MVC 2 and the Microsoft Ajax Library

demo

Why ASP.NET MVC 2 is Great!

> Separation of Concerns (Maintainability)> RenderAction()> Areas

> Validation (Maintainability/Productivity)> Data Annotations Support> Client Validation

> Helper Improvements (Maintainability/Productivity)> Strongly-Typed Helpers> Templated Helpers

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.