"
 
 
 
ASP.NET (snapshot 2017) Microsoft documentation and samples

ASP.NET MVC 4

This document describes the release of ASP.NET MVC 4 .

## Installation Notes

ASP.NET MVC 4 for Visual Studio 2010 can be installed from the ASP.NET MVC 4 home page using the Web Platform Installer.

We recommend uninstalling any previously installed previews of ASP.NET MVC 4 prior to installing ASP.NET MVC 4. You can upgrade the ASP.NET MVC 4 Beta and Release Candidate to ASP.NET MVC 4 without uninstalling.

This release is not compatible with any preview releases of .NET Framework 4.5. You must separately upgrade the any installed preview releases of .NET Framework 4.5 to the final version prior to installing ASP.NET MVC 4.

ASP.NET MVC 4 can be installed and run side-by-side with ASP.NET MVC 3.

## Documentation

Documentation for ASP.NET MVC is available on the MSDN website at the following URL:

https://go.microsoft.com/fwlink/?LinkID=243043

Tutorials and other information about ASP.NET MVC are available on the MVC 4 page of the ASP.NET website (https://www.asp.net/mvc/mvc4).

## Support

ASP.NET MVC 4 is fully supported. If you have questions about working with this release you can also post them to the ASP.NET MVC forum (https://forums.asp.net/1146.aspx), where members of the ASP.NET community are frequently able to provide informal support.

## Software Requirements

The ASP.NET MVC 4 components for Visual Studio require PowerShell 2.0 and either Visual Studio 2010 with Service Pack 1 or Visual Web Developer Express 2010 with Service Pack 1.

## New Features in ASP.NET MVC 4

This section describes features that have been introduced in the ASP.NET MVC 4 release.

### ASP.NET Web API

ASP.NET MVC 4 includes ASP.NET Web API, a new framework for creating HTTP services that can reach a broad range of clients including browsers and mobile devices. ASP.NET Web API is also an ideal platform for building RESTful services.

ASP.NET Web API includes support for the following features:

For more details on ASP.NET Web API please visit https://www.asp.net/web-api.

### Enhancements to Default Project Templates

The template that is used to create new ASP.NET MVC 4 projects has been updated to create a more modern-looking website:

In addition to cosmetic improvements, there???s improved functionality in the new template. The template employs a technique called adaptive rendering to look good in both desktop browsers and mobile browsers without any customization.

To see adaptive rendering in action, you can use a mobile emulator or just try resizing the desktop browser window to be smaller. When the browser window gets small enough, the layout of the page will change.

### Mobile Project Template

If you???re starting a new project and want to create a site specifically for mobile and tablet browsers, you can use the new Mobile Application project template. This is based on jQuery Mobile, an open-source library for building touch-optimized UI:

This template contains the same application structure as the Internet Application template (and the controller code is virtually identical), but it???s styled using jQuery Mobile to look good and behave well on touch-based mobile devices. To learn more about how to structure and style mobile UI, see the jQuery Mobile project website.

If you already have a desktop-oriented site that you want to add mobile-optimized views to, or if you want to create a single site that serves differently styled views to desktop and mobile browsers, you can use the new Display Modes feature. (See the next section.)

### Display Modes

The new Display Modes feature lets an application select views depending on the browser that???s making the request. For example, if a desktop browser requests the Home page, the application might use the Views.cshtml template. If a mobile browser requests the Home page, the application might return the Views.mobile.cshtml template.

Layouts and partials can also be overridden for particular browser types. For example:

If you want to create more specific views, layouts, or partial views for other devices, you can register a new DefaultDisplayMode instance to specify which name to search for when a request satisfies particular conditions. For example, you could add the following code to the Application_Start method in the Global.asax file to register the string ???iPhone??? as a display mode that applies when the Apple iPhone browser makes a request:

[!code-csharpMain]

   1:  DisplayModeProvider.Instance.Modes.Insert(0, new
   2:  DefaultDisplayMode("iPhone")
   3:  {
   4:      ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf
   5:          ("iPhone", StringComparison.OrdinalIgnoreCase) >= 0)
   6:  });

After this code runs, when an Apple iPhone browser makes a request, your application will use the Views\_Layout.iPhone.cshtml layout (if it exists). For more information on Display Mode, see ASP.NET MVC 4 Mobile Features. Applications using DisplayModeProvider should install the Fixed DisplayModes NuGet package. The ASP.NET Fall 2012 Update includes the Fixed DisplayModes NuGet package in the new project templates. See ASP.NET MVC 4 Mobile Caching Bug Fixedd for details on the fix.

### jQuery Mobile and Mobile Features

For information on building Mobile applications with ASP.NET MVC 4 using jQuery Mobile, see the tutorial ASP.NET MVC 4 Mobile Features.

### Task Support for Asynchronous Controllers

You can now write asynchronous action methods as single methods that return an object of type Task or Task<ActionResult>.

For more information see Using Asynchronous Methods in ASP.NET MVC 4.

### Azure SDK

ASP.NET MVC 4 supports the 1.6 and newer releases of the Windows Azure SDK.

### Database Migrations

ASP.NET MVC 4 projects now include Entity Framework 5. One of the great features in Entity Framework 5 is support for database migrations. This feature enables you to easily evolve your database schema using a code-focused migration while preserving the data in the database. For more information on database migrations, see Adding a New Field to the Movie Model and Table in the Introduction to ASP.NET MVC 4 tutorial.

### Empty Project Template

The MVC Empty project template is now truly empty so that you can start from a completely clean slate. The earlier version of the Empty project template has been renamed to Basic.

### Add Controller to any project folder

You can now right click and select Add Controller from any folder in your MVC project. This gives you more flexibility to organize your controllers however you want, including keeping your MVC and Web API controllers in separate folders.

### Bundling and Minification

The bundling and minification framework enables you to reduce the number of HTTP requests that a Web page needs to make by combining individual files into a single, bundled file for scripts and CSS. It can then reduce the overall size of those requests by minifying the contents of the bundle. Minifying can include activities like eliminating whitespace to shortening variable names to even collapsing CSS selectors based on their semantics. Bundles are declared and configured in code and are easily referenced in views via helper methods which can generate either a single link to the bundle or, when debugging, multiple links to the individual contents of the bundle. For more information see Bundling and Minification.

### Enabling Logins from Facebook and Other Sites Using OAuth and OpenID

The default templates in ASP.NET MVC 4 Internet Project template now includes support for OAuth and OpenID login using the DotNetOpenAuth library. For information on configuring an OAuth or OpenID provider, see OAuth/OpenID Support for WebForms, MVC and WebPages and the OAuth and OpenID feature documentation in ASP.NET Web Pages.

## Upgrading an ASP.NET MVC 3 Project to ASP.NET MVC 4

ASP.NET MVC 4 can be installed side by side with ASP.NET MVC 3 on the same computer, which gives you flexibility in choosing when to upgrade an ASP.NET MVC 3 application to ASP.NET MVC 4.

The simplest way to upgrade is to create a new ASP.NET MVC 4 project and copy all the views, controllers, code, and content files from the existing MVC 3 project to the new project and then to update the assembly references in the new project to match any non-MVC template included assembiles you are using. If you have made changes to the Web.config file in the MVC 3 project, you must also merge those changes into the Web.config file in the MVC 4 project.

To manually upgrade an existing ASP.NET MVC 3 application to version 4, do the following:

  1. In all Web.config files in the project (there is one in the root of the project, one in the Views folder, and one in the Views folder for each area in your project), replace every instance of the following text (note: System.Web.WebPages, Version=1.0.0.0 is not found in projects created with Visual Studio 2012):

    [!code-consoleMain]

       1:  System.Web.Mvc, Version=3.0.0.0
       2:  System.Web.WebPages, Version=1.0.0.0
       3:  System.Web.Helpers, Version=1.0.0.0
       4:  System.Web.WebPages.Razor, Version=1.0.0.0

    with the following corresponding text:

    [!code-consoleMain]
       1:  System.Web.Mvc, Version=4.0.0.0
       2:  System.Web.WebPages, Version=2.0.0.0
       3:  System.Web.Helpers, Version=2.0.0.0
       4:  System.Web.WebPages.Razor, Version=2.0.0.0
  2. In the root Web.config file, update the webPages:Version element to ???2.0.0.0??? and add a new PreserveLoginUrl key that has the value ???true???:

    [!code-xmlMain]
       1:  <appSettings>
       2:    <add key="webpages:Version" value="2.0.0.0" />
       3:    <add key="PreserveLoginUrl" value="true" />
       4:  </appSettings>
  3. In Solution Explorer, right-click on the References and select Manage NuGet Packages. In the left pane, select Onlineofficial package source, then update the following:

    • ASP.NET MVC 4
    • (Optional) jQuery, jQuery Validation and jQuery UI
    • (Optional) Entity Framework
    • (Optonal) Modernizr
  4. In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.
  5. Locate the ProjectTypeGuids element and replace {E53F8FEA-EAE0-44A6-8774-FFD645390401} with {E3E379DF-F4C6-4180-9B81-6769533ABE47}.
  6. Save the changes, close the project (.csproj) file you were editing, right-click the project, and then select Reload Project.
  7. If the project references any third-party libraries that are compiled using previous versions of ASP.NET MVC, open the root Web.config file and add the following three bindingRedirect elements under the configuration section:

    [!code-xmlMain]

       1:  <configuration>
       2:    <!--... elements deleted for clarity ...-->
       3:   
       4:    <runtime>
       5:      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
       6:        <dependentAssembly>
       7:          <assemblyIdentity name="System.Web.Helpers" 
       8:               publicKeyToken="31bf3856ad364e35" />
       9:          <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
      10:        </dependentAssembly>
      11:        <dependentAssembly>
      12:          <assemblyIdentity name="System.Web.Mvc" 
      13:               publicKeyToken="31bf3856ad364e35" />
      14:          <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0"/>
      15:        </dependentAssembly>
      16:        <dependentAssembly>
      17:          <assemblyIdentity name="System.Web.WebPages" 
      18:               publicKeyToken="31bf3856ad364e35" />
      19:          <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
      20:        </dependentAssembly>
      21:      </assemblyBinding>
      22:    </runtime>
      23:  </configuration>

## Changes from ASP.NET MVC 4 Release Candidate

The release notes for ASP.NET MVC 4 Release Candidate can be found here:

The major changes from ASP.NET MVC 4 Release Candidate in this release are summarized below:

## Known Issues and Breaking Changes

The following methods were also removed:

- *MvcCSharpRazorCodeParser.ParseInheritsStatement(System.Web.Razor.Parser.CodeBlockInfo)*
- *MvcWebPageRazorHost.DecorateCodeGenerator(System.Web.Razor.Generator.RazorCodeGenerator)*
- *MvcVBRazorCodeParser.ParseInheritsStatement(System.Web.Razor.Parser.CodeBlockInfo)*




Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnet/whitepapers/mvc4-release-notes.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>