Difference between ASP.NET MVC 3 and 4?

Is there an exhaustive list that explains all the new features of MVC4 and that everything has changed with MVC3?

( release notes are not very useful)

+63
asp.net-mvc asp.net-mvc-3 asp.net-mvc-4
Sep 21 '12 at 17:30
source share
6 answers

Copied and pasted from MVC4 Release Notes :

β€’ Modern HTTP programming model . Directly access and process HTTP requests and responses in your web APIs using the new, strongly typed HTTP object model. The same programming model and HTTP pipeline are symmetrically available on the client using the new HttpClient type.

β€’ Full Route Support : ASP.NET Web API supports a complete set of ASP.NET routing routing capabilities, including route parameters and restrictions. In addition, use simple conventions to map actions to HTTP methods.

β€’ Consolidation of content . The client and server can work together to determine the correct format for the data returned from the web API. The ASP.NET Web API provides standard support for XML, JSON, and Form formats for URL-encoded formats, and you can extend this support by adding your own formatting elements or even replacing the default content negotiation strategy.

β€’ model binding and validation . Interactive models provide an easy way to extract data from various parts of an HTTP request and convert these parts of messages to .NET objects that can be used by web API actions. Validation is also performed with action parameters based on data annotations.

β€’ Filters . The ASP.NET Web API supports filters, including well-known filters, such as the [Authorize] attribute. You can create and filter your own filters for actions, authorization and exception handling.

β€’ Composition of the request . Use the [Queryable] filter attribute for the action that returns IQueryable to enable support for the web API request through OData query conventions.

β€’ Improved testability . Instead of setting HTTP data in static context objects, the web API actions work with HttpRequestMessage and HttpResponseMessage instances. Create a unit test project with your web API project to get you started quickly writing unit tests for your web API functions.

β€’ Code based configuration . ASP.NET web API configuration is done exclusively with code, leaving your configuration files clean. Use the service provisioning template to configure extensibility points.

β€’ Improved support for inverse management containers (IoC) : ASP.NET Web API provides greater support for IoC containers through enhanced dependency resolver abstraction

β€’ Self-host . Web interfaces can be hosted in your own process in addition to IIS, while using all the features of routes and other functions of the web API.

β€’ Create user help and test pages . Now you can easily create custom help and test pages for your web APIs using the new IApiExplorer service to get a full description of your web interfaces. / P>

β€’ Monitoring and diagnostics . ASP.NET's web interface now provides a lightweight tracing infrastructure that makes it easy to integrate with existing logging solutions such as System.Diagnostics, ETW, and third-party logging structures. You can enable tracing by providing an implementation of ITraceWriter and adding it to your web API configuration.

β€’ Link generation . Use the ASP.NET Web API UrlHelper API to create links to related resources in one application.

β€’ Web API project template . Select a new web API project from the New MVC 4 project wizard to quickly start and start using the ASP.NET Web API.

β€’ Forests . Use the Add Controller dialog box to quickly create an API web controller based on an Entity Framework model type.

+61
Sep 21 '12 at 17:34
source share

Copy and paste from What's New in MVC4 - MVC3 Vs MVC4

What's New in MVC4 - MVC3 Vs MVC4

Default project template enhancements

The template used to create new ASP.NET MVC 4 projects has been updated to create a more modern website.

Mobile Project Template

If you are 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. It is based on jQuery Mobile, an open source library for creating a touch optimized user interface

Display modes

The new "Display Modes" feature allows the application to select views depending on the browser making the request. For example, if the desktop browser requests the main page, the application may use the Views\Home\Index.cshtml . If the mobile browser requests the main page, the application may return the Views\Home\Index.mobile.cshtml .

 DisplayModes.Modes.Insert(0, new DefaultDisplayMode("iPhone") { ContextCondition = (context => context.Request.UserAgent.IndexOf ("iPhone", StringComparison.OrdinalIgnoreCase) >= 0) }); 

jQuery Mobile, browse switch and browser browser

jQuery Mobile is an open source library for building a web interface with an optimized touch interface. If you want to use jQuery Mobile with ASP.NET MVC 4, you can download and install the NuGet package to get you started. To install it from the Visual Studio Package Manager console, enter the following command: Install-Package jQuery.Mobile.MVC This installs jQuery Mobile and some supporting files, including: Views / Shared / Layout.Mobile.cshtml, which is a jQuery layout Mobile A view-switcher component that consists of a partial view Views / Shared / ViewSwitcher.cshtml and a ViewSwitcherController.cs controller. After installing the package, launch the application using a mobile browser (or its equivalent, for example, an add-on for the User Agent User Manager switch). You will see that your pages look completely different because jQuery Mobile handles layout and style. To take advantage of this, you can do the following: If visitors click on a link, theyre switched to the desktop version of the same page. Since your default desktop layout will not include a view switch, visitors will have no way to switch to mobile mode. To enable this, add the following link: _ViewSwitcher for your desktop, only inside the element:

 @Html.Partial("_ViewSwitcher") 

... Browser redefinition is the main feature of ASP.NET MVC 4 and is accessible even if you do not install jQuery.Mobile.MVC package. However, it only affects the choice of view, layout, and partial view β€” it does not affect another ASP.NET function, which depends on the Request.Browser object.

Recipes for generating code in Visual Studio

The new Recipes feature allows Visual Studio to generate solution-specific code based on packages that can be installed using NuGet. The Recipes framework allows developers to write plug-ins for code generation, which you can also use to replace the built-in code generators for Add Area, Add Controller and Add View. Because recipes are deployed as NuGet packages, they can be easily checked in the source control and shared automatically for all developers in the project. They are also available for every solution.

Task support for asynchronous controllers

Now you can write asynchronous action methods as single methods that return an object of type Task or Task.

For example, if you are using Visual C # 5 (or using Async CTP), you can create an asynchronous action method that looks like this:

 public async Task Index(string city) { var newsService = new NewsService(); var sportsService = new SportsService(); return View("Common", new PortalViewModel { NewsHeadlines = await newsService.GetHeadlinesAsync(), SportsScores = await sportsService.GetScoresAsync() }); } 

In the previous action method, calls to newsService.GetHeadlinesAsync and sportsService.GetScoresAsync are called asynchronously and do not block the thread from the thread pool.

Asynchronous action methods that return Task instances can also support timeouts. To have your action method canceled, add a parameter of type CancellationToken to the signature of the action method. The following example shows an asynchronous action method that has a wait time of 2500 milliseconds and displays a TimedOut view to the client if a timeout occurs.

 [AsyncTimeout(2500)] [HandleError(ExceptionType = typeof(TaskCanceledException), View = "TimedOut")] public async Task 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) }); } 

Hope this helps. Thanks

+42
Sep 21 '12 at 18:35
source share
+2
Nov 25 '13 at 7:31
source share

MVC 3

  • Integrated Forest System Expandable Through NuGet
  • HTML 5 Support Project Templates
  • Expressive views, including the new look of the Razor Engine
  • Powerful dependency injection hooks and Global action filters
  • Rich JavaScript support with unobtrusive JavaScript, jQuery validation and JSON binding

MVC 4

  • ASP.NET Web API
  • Updated and modernized project by default. Templates
  • New mobile project template
  • Many new features for mobile app support
  • Extended support for asynchronous methods

Link: http://dotnet-developers-cafe.blogspot.in/2013/09/difference-between-aspnet-mvc-3-and-mvc.html

+1
Jan 15 '14 at 11:10
source share

One of the important features introduced in MVC 4.0 is asynchronous controllers, which allow you to write asynchronous action methods. Asynchronous controller allows you to perform an operation without downtime.

When an asynchronous action is called, the following steps are performed:

The web server receives the stream from the thread pool (worker thread) and plans to process the incoming request. This worker thread initiates an asynchronous operation. The workflow is returned to the thread pool to serve another web request. When the asynchronous operation is completed, it notifies ASP.NET. The web server receives a workflow from the thread pool (which may be another thread from the thread that started the asynchronous operation) to handle the rest of the request, including rendering the response.

Convert synchronous action methods to asynchronous action methods

The following is an example of a synchronous action method and its asynchronous equivalent version.

Synchronous controller:

  public class TestController : Controller { public ActionResult Index() { return View(); } } 

Asynchronous version of the above operation:

 public class TestController : AsyncController { public void IndexAsync() { return View(); } public ActionResult IndexCompleted() { return View(); } } 

Steps:

  • Synchronous controllers are classes that are derived from the class controller to implement AsyncController instead of receiving the controller from the controller, derive it from the AsyncController class. The controllers that are manufactured by AsyncController allow ASP.NET to handle asynchronous requests, and they can still handle synchronous action methods.

  • In accordance with the synchronous action method in synchronous mode, the controller needs to create two methods for acting on the asynchronous controller. The first method that initiates the asynchronous process should have a name consisting of the action and the suffix "Asynchronous". Another method that is called when an asynchronous process termination (callback method) must have a name that consists of an action and the suffix "Completed".

    In the example example above, the action of the index was converted to two methods in the asynchronous controller: IndexAsync and IndexCompleted.

    The IndexAsync method returns void, while the IndexCompleted method returns an ActionResult instance. Although the action consists of two methods, it is accessed using the same URL as the synchronous one (for example, Controller / Index).

Note the following asynchronous action methods:

If the action name is Sample, the Framework will look for the SampleAsync and SampleCompleted methods.

View pages should be named Sample.aspx, not SampleAsync.aspx or SampleCompleted.aspx. (The action name is Sample, not SampleAsync)

The controller cannot contain an asynchronous method named SampleAsync and a synchronous method named Sample. If so, an AmbiguousMatchException is thrown because the SampleAsync action method and the Sample action method have the same request signature.

For more information, click here: http://www.counsellingbyabhi.com/2014/05/asynchronous-controllers-in-aspnet-mvc.html

0
May 05 '14 at 8:26
source share



All Articles