Top Banner
Microsoft ASP.NET MVC 2: The New Stuff Stephen Walther Senior Program Manager Microsoft Corporation PDC09-FT22
29
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Everything starts so simple, but then…

Microsoft ASP.NET MVC 2: The New Stuff

Stephen WaltherSenior Program ManagerMicrosoft Corporation

PDC09-FT22

Page 2: Everything starts so simple, but then…

ASP.NET MVC 1.0

Everything starts so simple, but then…

Page 3: Everything starts so simple, but then…

ASP.NET MVC 1.0

Page 4: Everything starts so simple, but then…

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

Page 5: Everything starts so simple, but then…

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

Page 6: Everything starts so simple, but then…

ASP.NET MVC 2

Visual Studio 2010Included

Visual Studio 2008 (Service Pack 1)Download

Both versions built against .NET 3.5

Page 7: Everything starts so simple, but then…

RenderAction (Composability)

<% Html.RenderAction() %>

> Menus> Banner Ads> Shopping Carts

Any UI that appears in multiple pages and requires business logic

Page 8: Everything starts so simple, but then…

RenderAction (Maintainability)

> Html.RenderPartial()Renders UI

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

Page 9: Everything starts so simple, but then…

Using RenderAction

demo

Page 10: Everything starts so simple, but then…

Areas (Maintainability)

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

AreaRegistration.RegisterAllAreas();

Page 11: Everything starts so simple, but then…

Using Areas

demo

Page 12: Everything starts so simple, but then…

Validation (Maintainability/Productivity)

Client-Side Validation

Server-Side Validation

Model Class

Define Validation

Page 13: Everything starts so simple, but then…

Validation (Maintainability/Productivity)> Model Validation Providers

> Data Annotation (Default)> Enterprise Library> XML

Anything you want

Page 14: Everything starts so simple, but then…

Validation (Maintainability/Productivity)Data Annotation Validators

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

Page 15: Everything starts so simple, but then…

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; }}

Page 16: Everything starts so simple, but then…

Server-Side Validation with Data Annotations

demo

Page 17: Everything starts so simple, but then…

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(); %>

Page 18: Everything starts so simple, but then…

Client-Side Validation

demo

Page 19: Everything starts so simple, but then…

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

Page 20: Everything starts so simple, but then…

Templated Helpers (Productivity)

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

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

Page 21: Everything starts so simple, but then…

Templated Helpers (Productivity)

Specify Template:> By Type:

DateTime.ascx

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

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

Page 22: Everything starts so simple, but then…

Templated Helpers (Productivity)

Fallback:> Employee> Person> Object

Page 23: Everything starts so simple, but then…

Templated Helpers

demo

Page 24: Everything starts so simple, but then…

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

Page 25: Everything starts so simple, but then…

Value Providers

Source for Model Binder data:

> FormValueProvider> RouteDataValueProvider> QueryStringValueProvider> HttpFileCollectionValueProvider

and custom…

Page 26: Everything starts so simple, but then…

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

demo

Page 27: Everything starts so simple, but then…

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

Page 28: Everything starts so simple, but then…

© 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.

Page 29: Everything starts so simple, but then…