310 likes | 671 Views
ASP.NET MVC 3. Jean-Claude Trachsel. Senior Consultant. Trivadis AG. Agenda. Overview N ew Features Summary. ASP.NET MVC 3. ASP.NET MVC 3 Many new Features. ASP.NET MVC 2 More Productivity , Security and Performance. ASP.NET MVC 1 Basic Features. ASP.NET MVC 1 Basic Features.
E N D
ASP.NET MVC 3 Jean-Claude Trachsel Senior Consultant Trivadis AG
Agenda • Overview • New Features • Summary
ASP.NET MVC 3 ASP.NETMVC 3 Manynew Features ASP.NET MVC 2 More Productivity, Security and Performance ASP.NET MVC 1 Basic Features ASP.NET MVC 1 Basic Features
ASP.NET MVC 3 • It can be installed side-by-side with MVC 2 • It requires the .NET Framework 4 • Actual release is Beta
Manynew FeaturesAndmanymore… • Global Filters • Dynamic ViewModel Property • New ActionResultTypes • Model Validation Support • Ajax andjQuery Support • DependencyInjection Support • Razor View Engine
Global FiltersAspect Oriented Programing • New possibility to apply a filter to all controllers • Conditional filters thruIFilterProvider Demo
ViewModelNew Dynamic Property • Uses .NET 4 dynamicdatatype • Cleaner solutiontoworkwiththeViewModel • Nostringsaskeyanymore
ViewData vs. ViewModel ViewData["Message"]="Welcome to ASP.NET MVC!"; <div><%:ViewContext.ViewData["Message"]%></div> ViewModel.Message="Welcome to ASP.NET MVC 3!"; <div>@View.Message</div> MVC 2 MVC 3
ActionResultNew Types • HttpNotFoundResult • HttpRedirectResult • HttpStatusCodeResult
HttpNotFoundResult publicActionResultAbout() { returnHttpNotFound(); }
Model Validation • Supports new .Net 4 DataAnnotations Features • DisplayAttribute • New IsValidoverloads in theValidationAttribute • IValidatableObject Demo
Ajax andjQuery • Many new Ajax and jQueryfeatures • Visittheafternoonsession • ASP.NET MVC 3 specific • JsonValueProviderFactory
Model bindingsupportASP.NET MVC 2 Form&Fields Step 1 Edit fields on the form in thebrowser
Model bindingsupportASP.NET MVC 2 Form&Fields Controller Action Post Step 2 Post the form totheserver. The routingenginecallsthecontroller
Model bindingsupportASP.NET MVC 2 Form&Fields Controller Action Object& Property Post ModelBinder Step 3 Instanciatetheentityobjectandsetpropertiestothe form values
JsonbindingsupportASP.NET MVC 3 Form&Fields Step 1 Edit fields on the form in thebrowser
JsonbindingsupportASP.NET MVC 3 Json Form&Fields jQuery Step 2 GenerateJsonobject on theclientwithjQuery
JsonbindingsupportASP.NET MVC 3 Form&Fields Controller Action Ajax Post Step 3 Post theJsonobjectasynchron totheserver
JsonbindingsupportASP.NET MVC 3 Form&Fields Controller Action Object&Property Post Jason Value Provider Step 4 Instanciatetheentityobjectandsetpropertiestothejsonvalues
DependencyInjection • ASP.NET MVC 3 supports • Common Service Locator library • Any DI container supporting it’s IServiceLocatorinterface • Common Service Locator library is supportedby • Unity • Spring.NET • Castle Windsor • StructureMap
MVC 3 DI support • MVC 3 beta • Controllers (registering & injecting controller factories, injecting controllers) • Views (registering & injecting view engines, injecting dependencies into view pages) • Action Filters (locating & injecting filters) • MVC 3 RC • Model Binders (registering & injecting) • Value Providers (registering & injecting) • Validation Providers (registering & injecting) • Model metadata Providers (registering & injecting)
View Engines • ASP.NET (aspx) * • Razor * • Spark • NHaml • NDjango * Included in Visual Studio 2010
WhatisRazor?Design goalsofRazor • Compact, Expressive and Fluid • Easy to learn • Is not a new language • Works with any Text Editor • Has great Intellisense and syntax highlighting
Razoradvantages • 1 characterinsteadof 5 forcodeblocks • Razor: @ (noclosing tag needed)Parser has semantic knowledge of C# / VB • Aspx: <%: %> • Coding is fast, fluid and fun
«Hello World» aspx <%@PageLanguage="C#"MasterPageFile="~/Views/Shared/Site.Master“Inherits="System.Web.Mvc.ViewPage<Product>"%> <asp:ContentID="aboutTitle"ContentPlaceHolderID="TitleContent“ runat="server"> Razor Demo </asp:Content> <asp:ContentID="aboutContent"ContentPlaceHolderID="MainContent"runat="server"> <h2>Razor Demo</h2> Hello World, we got Number 1: <%: Model.Number1 %> and Number 2: <%: Model.Number1 %>. </asp:Content> @model Trivadis.Models.Product @{View.Title = "Razor Demo";} <h2>Razor Demo</h2> Hello World, we got Number 1: @Model.Number1 and Number 2: @Model.Number2. Razor
Razorsyntax • Multiline statements • if(){}, foreach(){} • Layout/MasterPage concept • _viewstart.cshtmlconcept Demo
Summary • Many helpful new features • Great IoC and DI support • PerfectData Annotationssupport • Razor, a clean, fast and fun approach
SwissPDC10@Trivadis • Termin: 28.10.2010 • Ort: Zürich - in der Trivadis Niederlassung • Agenda: • 16:00 h: Registrierung und Begrüssungskaffee • 16:30 h: Silverlight, Azureand WP7 • 17:30 h: Pause mit Verpflegung • 18:00 h: KeynotePDC10 mit Steve Ballmer • 20:00 h: Pause mit Verpflegung • 20:30 h: Podiumsdiskussion: "Was bedeuten die Ankündigung für die Praxis" • 21:30 h: Verlosung der Preise
© 2010 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.