SlideShare a Scribd company logo
ASP.NET MVC 4
Developer Preview
    Jon Galloway
  SoCal Code Camp
Agenda
• Overall focus areas for ASP.NET MVC 4
• Installation overview and availability
• Top new features
Overall focus areas for ASP.NET MVC 4
Goal: Make ASP.NET MVC the best web platform for
building modern rich web apps

Themes
• Development and deployment
  Capitalize on the platform
   – The Razor view engine and some of the new helpers in ASP.NET MVC 3 came out of work done
     for ASP.NET Web Pages.
• Ajax
   – “Dash of Ajax”
   – Full single-page application
• HTML5, tablet, and mobile
• Cloud ready
Notable Breaking Changes
• There are issues when running ASP.NET
  MVC 3, ASP.NET MVC 4, and Windows Azure
  Tools for Visual Studio 2010 1.5 side by side.
• Installing ASP.NET MVC 4 Developer Preview
  breaks ASP.NET MVC 3 RTM (but not the
  ASP.NET MVC 3 Tool Update) applications.

• Workarounds detailed in release notes.
Requirements
• ASP.NET MVC 4: .NET Framework 4
• Tooling:
  – Visual Studio 2010 with Service Pack 1 or
  – Visual Web Developer Express 2010 with SP1
Major Features in MVC 4
• Enhancements to Default Project Templates
• Display Modes
• jQuery Mobile, the View Switcher, and
  Browser Overriding
• Mobile Project Template
• Recipes for Code Generation in Visual Studio
• Task Support for Asynchronous Controllers
Default Template Changes
• New Design
• Adaptive Rendering
Custom Modes
DisplayModes.Modes.Insert(0, new DefaultDisplayMode("iPhone")
{
    ContextCondition = (context =>
context.Request.UserAgent.IndexOf
        ("iPhone", StringComparison.OrdinalIgnoreCase) >= 0)
});




ViewsShared_Layout.iPhone.cshtml
Major Features in MVC 4
• Enhancements to Default Project Templates
• Display Modes
• jQuery Mobile, the View Switcher, and
  Browser Overriding
• Mobile Project Template
• Recipes for Code Generation in Visual Studio
• Task Support for Asynchronous Controllers
jQuery Mobile – Browser Switcher




   <body>
       @Html.Partial("_ViewSwitcher")
Recipes
• Modular tooling installed via NuGet
SoCal Code Camp 2011 - ASP.NET MVC 4
Async Support
[AsyncTimeout(2500)]
[HandleError(ExceptionType = typeof(TaskCanceledException), View = "TimedOut")]
public async Task<ActionResult> Index(string city,
    CancellationToken cancellationToken) {


    var newsService = new NewsService();
    var sportsService = new SportsService();


    return View("Common",
          new PortalViewModel {
          NewsHeadlines = await newsService.GetHeadlinesAsync(cancellationToken),
          SportsScores = await sportsService.GetScoresAsync(cancellationToken)
    });
}
Async Support
[AsyncTimeout(2500)]
[HandleError(ExceptionType = typeof(TaskCanceledException), View = "TimedOut")]
public async Task<ActionResult> Index(string city,
    CancellationToken cancellationToken) {


    var newsService = new NewsService();
    var sportsService = new SportsService();


    return View("Common",
          new PortalViewModel {
          NewsHeadlines = await newsService.GetHeadlinesAsync(cancellationToken),
          SportsScores = await sportsService.GetScoresAsync(cancellationToken)
    });
}
Other Goodies
Other Features (listed in public roadmap)
We haven’t spent time fleshing out every feature under consideration. The following items are on the top of
our mind. Some of them will be delivered by other teams.
•   CSS and JavaScript Bundling Integration ASP.NET MVC 4 will include CSS and JavaScript bundling. Bundling
    consolidates .css and .js files by combining multiple files into a single file and reduces the total size of the
    resulting (combined) file by removing unnecessary whitespace and comments (minification). This reduces
    both bandwidth usage and download times, which speeds up the rendering of web pages.
•   EF Code First Data Migrations. This provides support for migrating from one version of your database
    schema to the next without losing data.
•   Better support for functional and integration testing of application code.
•   WCF Web API support.
•   Ajax improvements across the board. We’re focusing reducing the friction that developers encounter
    when using Ajax with ASP.NET MVC.
•   HTML5 support for editor/display templates and HTML helpers. For example, editor templates to might
    render an input element with its type set to date instead of an input element with its type set to the
    default text when rendering a DateTime property. Likewise, existing HTML helpers such as TextBoxFor
    might also be updated to render an appropriate input element based on the model type.
•   Support for “donut hole” caching in Razor views and support for the Windows Server App Fabric caching
    provider.
•   A new AreaAttribute class for better security when using areas.

More Related Content

SoCal Code Camp 2011 - ASP.NET MVC 4

  • 1. ASP.NET MVC 4 Developer Preview Jon Galloway SoCal Code Camp
  • 2. Agenda • Overall focus areas for ASP.NET MVC 4 • Installation overview and availability • Top new features
  • 3. Overall focus areas for ASP.NET MVC 4 Goal: Make ASP.NET MVC the best web platform for building modern rich web apps Themes • Development and deployment Capitalize on the platform – The Razor view engine and some of the new helpers in ASP.NET MVC 3 came out of work done for ASP.NET Web Pages. • Ajax – “Dash of Ajax” – Full single-page application • HTML5, tablet, and mobile • Cloud ready
  • 4. Notable Breaking Changes • There are issues when running ASP.NET MVC 3, ASP.NET MVC 4, and Windows Azure Tools for Visual Studio 2010 1.5 side by side. • Installing ASP.NET MVC 4 Developer Preview breaks ASP.NET MVC 3 RTM (but not the ASP.NET MVC 3 Tool Update) applications. • Workarounds detailed in release notes.
  • 5. Requirements • ASP.NET MVC 4: .NET Framework 4 • Tooling: – Visual Studio 2010 with Service Pack 1 or – Visual Web Developer Express 2010 with SP1
  • 6. Major Features in MVC 4 • Enhancements to Default Project Templates • Display Modes • jQuery Mobile, the View Switcher, and Browser Overriding • Mobile Project Template • Recipes for Code Generation in Visual Studio • Task Support for Asynchronous Controllers
  • 7. Default Template Changes • New Design • Adaptive Rendering
  • 8. Custom Modes DisplayModes.Modes.Insert(0, new DefaultDisplayMode("iPhone") { ContextCondition = (context => context.Request.UserAgent.IndexOf ("iPhone", StringComparison.OrdinalIgnoreCase) >= 0) }); ViewsShared_Layout.iPhone.cshtml
  • 9. Major Features in MVC 4 • Enhancements to Default Project Templates • Display Modes • jQuery Mobile, the View Switcher, and Browser Overriding • Mobile Project Template • Recipes for Code Generation in Visual Studio • Task Support for Asynchronous Controllers
  • 10. jQuery Mobile – Browser Switcher <body> @Html.Partial("_ViewSwitcher")
  • 11. Recipes • Modular tooling installed via NuGet
  • 13. Async Support [AsyncTimeout(2500)] [HandleError(ExceptionType = typeof(TaskCanceledException), View = "TimedOut")] public async Task<ActionResult> Index(string city, CancellationToken cancellationToken) { var newsService = new NewsService(); var sportsService = new SportsService(); return View("Common", new PortalViewModel { NewsHeadlines = await newsService.GetHeadlinesAsync(cancellationToken), SportsScores = await sportsService.GetScoresAsync(cancellationToken) }); }
  • 14. Async Support [AsyncTimeout(2500)] [HandleError(ExceptionType = typeof(TaskCanceledException), View = "TimedOut")] public async Task<ActionResult> Index(string city, CancellationToken cancellationToken) { var newsService = new NewsService(); var sportsService = new SportsService(); return View("Common", new PortalViewModel { NewsHeadlines = await newsService.GetHeadlinesAsync(cancellationToken), SportsScores = await sportsService.GetScoresAsync(cancellationToken) }); }
  • 15. Other Goodies Other Features (listed in public roadmap) We haven’t spent time fleshing out every feature under consideration. The following items are on the top of our mind. Some of them will be delivered by other teams. • CSS and JavaScript Bundling Integration ASP.NET MVC 4 will include CSS and JavaScript bundling. Bundling consolidates .css and .js files by combining multiple files into a single file and reduces the total size of the resulting (combined) file by removing unnecessary whitespace and comments (minification). This reduces both bandwidth usage and download times, which speeds up the rendering of web pages. • EF Code First Data Migrations. This provides support for migrating from one version of your database schema to the next without losing data. • Better support for functional and integration testing of application code. • WCF Web API support. • Ajax improvements across the board. We’re focusing reducing the friction that developers encounter when using Ajax with ASP.NET MVC. • HTML5 support for editor/display templates and HTML helpers. For example, editor templates to might render an input element with its type set to date instead of an input element with its type set to the default text when rendering a DateTime property. Likewise, existing HTML helpers such as TextBoxFor might also be updated to render an appropriate input element based on the model type. • Support for “donut hole” caching in Razor views and support for the Windows Server App Fabric caching provider. • A new AreaAttribute class for better security when using areas.