ASP的区别。NET MVC 3和4?

时间:2020-12-30 02:01:20

Is there a comprehensive list that explains all of the new features of MVC4 and what all has changed from MVC3?

是否有一个完整的列表来解释MVC4的所有新特性以及MVC3的所有变化?

(The release notes are not much helpful)

(发布说明没有多大帮助)

6 个解决方案

#1


61  

Copied and pasted from MVC4 Release Notes:

复制粘贴MVC4发行说明:

Modern HTTP programming model: Directly access and manipulate HTTP requests and responses in your Web APIs using a new, strongly typed HTTP object model. The same programming model and HTTP pipeline is symmetrically available on the client through the new HttpClient type.

•现代HTTP编程模型:使用新的强类型HTTP对象模型直接访问和操作Web api中的HTTP请求和响应。同样的编程模型和HTTP管道通过新的HttpClient类型在客户机上对称地可用。

Full support for routes: ASP.NET Web API supports the full set of route capabilities of ASP.NET Routing, including route parameters and constraints. Additionally, use simple conventions to map actions to HTTP methods.

•对路线的充分支持:ASP。NET Web API支持ASP的全套路由功能。NET路由,包括路由参数和约束。此外,使用简单的约定将操作映射到HTTP方法。

Content negotiation: The client and server can work together to determine the right format for data being returned from a web API. ASP.NET Web API provides default support for XML, JSON, and Form URL-encoded formats and you can extend this support by adding your own formatters, or even replace the default content negotiation strategy.

•内容协商:客户端和服务器可以共同确定从web API返回的数据的正确格式。ASP。NET Web API为XML、JSON和形式url编码格式提供了默认支持,您可以通过添加自己的格式器来扩展这种支持,甚至可以替换默认的内容协商策略。

Model binding and validation: Model binders provide an easy way to extract data from various parts of an HTTP request and convert those message parts into .NET objects which can be used by the Web API actions. Validation is also performed on action parameters based on data annotations.

•模型绑定和验证:模型绑定提供了一种简单的方法,可以从HTTP请求的各个部分提取数据,并将这些消息部分转换为. net对象,Web API操作可以使用这些对象。还根据数据注释对操作参数进行验证。

Filters: ASP.NET Web API supports filters including well-known filters such as the [Authorize] attribute. You can author and plug in your own filters for actions, authorization and exception handling.

•过滤器:ASP。NET Web API支持过滤器,包括众所周知的过滤器,如[Authorize]属性。您可以为操作、授权和异常处理创建并插入您自己的过滤器。

Query composition: Use the [Queryable] filter attribute on an action that returns IQueryable to enable support for querying your web API via the OData query conventions.

•查询组合:在返回IQueryable的操作上使用[Queryable]筛选属性,以支持通过OData查询约定查询web API。

Improved testability: Rather than setting HTTP details in static context objects, web API actions work with instances of HttpRequestMessage and HttpResponseMessage. Create a unit test project along with your Web API project to get started quickly writing unit tests for your Web API functionality.

•改进可测试性:web API操作与HTTP prequestmessage和HttpResponseMessage的实例一起工作,而不是在静态上下文对象中设置HTTP细节。与Web API项目一起创建一个单元测试项目,以快速开始为Web API功能编写单元测试。

Code-based configuration: ASP.NET Web API configuration is accomplished solely through code, leaving your config files clean. Use the provide service locator pattern to configure extensibility points.

•基于代码配置:ASP。NET Web API配置仅通过代码完成,使配置文件保持干净。使用“提供服务定位器”模式配置可扩展性点。

Improved support for Inversion of Control (IoC) containers: ASP.NET Web API provides great support for IoC containers through an improved dependency resolver abstraction

改进了对控制反转(IoC)容器的支持:ASP。NET Web API通过改进的依赖解析器抽象为IoC容器提供了很好的支持

Self-host: Web APIs can be hosted in your own process in addition to IIS while still using the full power of routes and other features of Web API.

•自宿主:除了IIS之外,Web API还可以托管在您自己的进程中,同时仍然充分利用路由和Web API的其他特性。

Create custom help and test pages: You now can easily build custom help and test pages for your web APIs by using the new IApiExplorer service to get a complete runtime description of your web APIs.

•创建自定义帮助和测试页面:现在您可以通过使用新的IApiExplorer服务来获得web api的完整运行时描述,从而轻松地为您的web api构建定制的帮助和测试页面。

Monitoring and diagnostics: ASP.NET Web API now provides light weight tracing infrastructure that makes it easy to integrate with existing logging solutions such as System.Diagnostics, ETW and third party logging frameworks. You can enable tracing by providing an ITraceWriter implementation and adding it to your web API configuration.

•监控和诊断:ASP。NET Web API现在提供了轻量级的跟踪基础设施,使得与现有的日志记录解决方案(如System)集成变得很容易。诊断、ETW和第三方日志记录框架。可以通过提供ITraceWriter实现并将其添加到web API配置来启用跟踪。

Link generation: Use the ASP.NET Web API UrlHelper to generate links to related resources in the same application.

•链接生成:使用ASP。NET Web API UrlHelper在同一个应用程序中生成与相关资源的链接。

Web API project template: Select the new Web API project form the New MVC 4 Project wizard to quickly get up and running with ASP.NET Web API.

•Web API项目模板:从新的MVC 4项目向导中选择新的Web API项目,使用ASP快速启动和运行。净Web API。

Scaffolding: Use the Add Controller dialog to quickly scaffold a web API controller based on an Entity Framework based model type.

•搭建:使用Add Controller对话框快速搭建基于实体框架模型类型的web API控制器。

#2


42  

Copy and paste from Whats new in MVC4 - MVC3 Vs MVC4

从MVC4 - MVC3和MVC4中复制粘贴新的内容

Whats new in MVC4 - MVC3 Vs MVC4

MVC4 - MVC3和MVC4有什么新东西

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

用于创建新的ASP的模板。NET MVC 4项目已经更新,以创建一个更加现代的网站。

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

如果您正在启动一个新项目,并希望为移动和平板浏览器创建一个站点,那么您可以使用新的移动应用程序项目模板。这是基于jQuery Mobile,一个用于构建触摸优化UI的开源库

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\Home\Index.cshtml template. If a mobile browser requests the Home page, the application might return the Views\Home\Index.mobile.cshtml template.

新的显示模式特性允许应用程序根据发出请求的浏览器选择视图。例如,如果桌面浏览器请求主页,应用程序可能会使用view \Home\Index。cshtml模板。如果移动浏览器请求主页,应用程序可能会返回视图\Home\Index.mobile。cshtml模板。

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

jQuery Mobile, the View Switcher, and Browser Overriding

jQuery Mobile、视图切换器和浏览器覆盖

jQuery Mobile is an open source library for building touch-optimized web UI. If you want to use jQuery Mobile with an ASP.NET MVC 4 application, you can download and install a NuGet package that helps you get started. To install it from the Visual Studio Package Manager Console, type the following command: Install-Package jQuery.Mobile.MVC This installs jQuery Mobile and some helper files, including the following: Views/Shared/Layout.Mobile.cshtml, which is a jQuery Mobile-based layout. A view-switcher component, which consists of the Views/Shared/ViewSwitcher.cshtml partial view and the ViewSwitcherController.cs controller. After you install the package, run your application using a mobile browser (or equivalent, like the Firefox User Agent Switcher add-on). You'll see that your pages look quite different, because jQuery Mobile handles layout and styling. To take advantage of this, you can do the following If visitors click the link, they’re switched to the desktop version of the same page. Because your desktop layout will not include a view switcher by default, visitors won't have a way to get to mobile mode. To enable this, add the following reference to _ViewSwitcher to your desktop layout, just inside the element:

jQuery Mobile是一个用于构建触摸优化的web UI的开源库。如果你想要使用jQuery手机和ASP。NET MVC 4应用程序,您可以下载并安装一个NuGet包,帮助您入门。要从Visual Studio包管理器控制台安装它,请输入以下命令:install -Package jQuery.Mobile。MVC安装jQuery Mobile和一些帮助文件,包括:view /Shared/Layout.Mobile。cshtml是一个基于jQuery移动的布局。一个视图切换组件,它由视图/共享/视图切换器组成。cshtml部分视图和ViewSwitcherController。cs控制器。安装完包后,使用移动浏览器(或类似的浏览器,如Firefox用户代理切换插件)运行应用程序。您将看到您的页面看起来非常不同,因为jQuery Mobile处理布局和样式。为了利用这个优势,如果访问者点击链接,他们就会切换到相同页面的桌面版本。由于您的桌面布局在默认情况下不包含视图切换器,访问者将无法进入移动模式。要实现这一点,将_ViewSwitcher以下引用添加到您的桌面布局中,就在元素内部:

@Html.Partial("_ViewSwitcher")

... Browser Overriding is a core feature of ASP.NET MVC 4 and is available even if you don't install the jQuery.Mobile.MVC package. However, it affects only view, layout, and partial-view selection — it does not affect any other ASP.NET feature that depends on the Request.Browser object.

…浏览器覆盖是ASP的一个核心特性。NET MVC 4,即使您不安装jQuery.Mobile,也可以使用。MVC包。但是,它只影响视图、布局和部分视图选择——它不影响任何其他ASP。取决于请求的NET特性。浏览器对象。

Recipes for Code Generation in Visual Studio

在Visual Studio中生成代码的方法。

The new Recipes feature enables Visual Studio to generate solution-specific code based on packages that you can install using NuGet. The Recipes framework makes it easy for developers to write code-generation plugins, 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 easily be checked into source control and shared with all developers on the project automatically. They are also available on a per-solution basis.

新的菜谱特性使Visual Studio能够基于您可以使用NuGet安装的包生成特定于解决方案的代码。recipe框架使开发人员很容易编写代码生成插件,您还可以使用这些插件替换用于添加区域、添加控制器和添加视图的内置代码生成器。由于菜谱是作为NuGet包部署的,因此可以很容易地将它们检入源代码控制并与项目中的所有开发人员自动共享。它们也可以在每个解决方案的基础上使用。

Task Support for Asynchronous Controllers

异步控制器的任务支持

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

现在,您可以将异步操作方法作为返回类型任务或任务的对象的单一方法来编写。

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

例如,如果您正在使用Visual c# 5(或使用Async CTP),您可以创建一个类似于以下内容的异步操作方法:

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, the calls to newsService.GetHeadlinesAsync and sportsService.GetScoresAsync are called asynchronously and do not block a thread from the thread pool.

在前面的操作方法中,调用newsService。GetHeadlinesAsync sportsService。GetScoresAsync是异步调用的,不会阻塞线程池中的线程。

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

返回任务实例的异步操作方法也可以支持超时。为了使您的操作方法可以被取消,在动作方法签名中添加一个类型取消令牌参数。下面的示例展示了一个异步操作方法,它的超时为2500毫秒,如果发生超时,它将向客户端显示TimedOut视图。

[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

希望这个有帮助。谢谢

#3


2  

Please go through the URL for all MVC 4 new features

请查看所有MVC 4的新特性的URL

#4


1  

MVC 3

MVC 3

  1. Integrated Scaffolding system extensible via NuGet
  2. 通过NuGet可扩展的集成脚手架系统。
  3. HTML 5 enabled project templates
  4. 支持HTML 5的项目模板
  5. Expressive Views including the new Razor View Engine
  6. 表达视图,包括新的Razor视图引擎。
  7. Powerful hooks with Dependency Injection and Global Action Filters
  8. 具有依赖注入和全局操作过滤器的强大钩子
  9. Rich JavaScript support with unobtrusive JavaScript, jQuery Validation, and JSON binding
  10. 丰富的JavaScript支持,不引人注目的JavaScript、jQuery验证和JSON绑定

MVC 4

MVC 4

  1. ASP.NET Web API
  2. ASP。净Web API
  3. Refreshed and modernized default project templates
  4. 更新和现代化的默认项目模板
  5. New mobile project template
  6. 新的移动项目模板
  7. Many new features to support mobile apps
  8. 许多新功能支持移动应用。
  9. Enhanced support for asynchronous methods
  10. 增强对异步方法的支持。

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

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

#5


0  

Please check the below links to find out the differences.

请查看下面的链接以了解差异。

http://forums.asp.net/t/1753017.aspx

http://forums.asp.net/t/1753017.aspx

http://www.askamoeba.com/Answer/130/Whats-new-in-MVC4-MVC3-Vs-MVC4

http://www.askamoeba.com/Answer/130/Whats-new-in-MVC4-MVC3-Vs-MVC4

http://forums.asp.net/t/1918539.aspx?Main+difference+between+regular+webapplication+mvc3+and+mvc4+

http://forums.asp.net/t/1918539.aspx?Main + +差+常规+ webapplication + mvc3 +和+ mvc4 +

#6


0  

One of the important feature introduced in MVC 4.0 was of Asynchronous controllers which enables to write the asynchronous action methods. Asynchronous controller allows an operation to get performed without making the working thread idle.

MVC 4.0引入的一个重要特性是异步控制器,它允许编写异步操作方法。异步控制器允许在不使工作线程空闲的情况下执行操作。

When an asynchronous action is invoked, the following steps occur:

当调用异步操作时,发生以下步骤:

The Web server gets a thread from the thread pool (the worker thread) and schedules it to handle an incoming request. This worker thread initiates an asynchronous operation. The worker thread is returned to the thread pool to service another Web request. When the asynchronous operation is complete, it notifies ASP.NET. The Web server gets a worker thread from the thread pool (which might be a different thread from the thread that started the asynchronous operation) to process the remainder of the request, including rendering the response.

Web服务器从线程池(工作线程)获取一个线程,并安排它处理传入的请求。这个工作线程启动一个异步操作。工作线程被返回到线程池以服务另一个Web请求。当异步操作完成时,它会通知ASP.NET。Web服务器从线程池(可能是与启动异步操作的线程不同的线程)获取工作线程,以处理请求的其余部分,包括呈现响应。

Converting Synchronous Action Methods to Asynchronous Action Methods

将同步操作方法转换为异步操作方法。

Following is the example of synchronous action method and the its asynchronous equivalent version.

下面是同步操作方法及其异步等效版本的示例。

Synchronous Controller:

同步控制器:

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

Asynchronous variant of above operation:

以上操作的异步变体:

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

  public ActionResult IndexCompleted()
  {
   return View();
  }
}

Steps:

步骤:

  • Synchronous Controllers are the classes derived from the Controller class to implement an AsyncController instead of deriving the controller from Controller, derive it from AsyncController class. Controllers that derive from AsyncController enable ASP.NET to process asynchronous requests, and they can still service synchronous action methods.

    同步控制器是从控制器类派生的类来实现异步控制器,而不是从控制器派生控制器,从异步控制器类派生控制器。从异步控制器派生的控制器支持ASP。NET处理异步请求,它们仍然可以服务同步操作方法。

  • Corresponding to the synchronous action method in Synchronous controller you need to create two methods for the action in asynchronous controller.First method that initiates the asynchronous process must have a name that consists of the action and the suffix "Async". The other method that is invoked when the asynchronous process finishes (the callback method) must have a name that consists of the action and the suffix "Completed".

    与同步控制器中的同步操作方法对应,需要为异步控制器中的操作创建两个方法。初始化异步进程的第一个方法必须有一个由动作和后缀“Async”组成的名称。当异步进程完成(回调方法)时调用的另一个方法必须有一个由动作和后缀“完成”组成的名称。

    In the above sample example, the Index action has been turned into two methods in asynchronous controller: IndexAsync and IndexCompleted.

    在上面的示例示例中,索引操作被转换为异步控制器中的两种方法:IndexAsync和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 for a synchronous action method (for example, Controller/Index).

    IndexAsync方法返回void,而indexcomplete方法返回一个ActionResult实例。尽管该操作由两种方法组成,但它使用与同步操作方法(例如,控制器/索引)相同的URL访问。

Note the following about asynchronous action methods:

注意以下关于异步操作方法的内容:

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

如果操作名是Sample,框架将查找SampleAsync和SampleCompleted方法。

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

视图页面应该命名为Sample。aspx而不是SampleAsync。aspx或SampleCompleted.aspx。(动作名是Sample,不是SampleAsync)

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

控制器不能包含名为SampleAsync的异步方法和名为Sample的同步方法。如果是,则抛出一个歧义匹配异常,因为SampleAsync操作方法和示例操作方法具有相同的请求签名。

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

有关更多细节,请点击这里:http://www.consullingbyabhi.com/2014/05/asynchronous -controllers in-aspnet-mvc.html

#1


61  

Copied and pasted from MVC4 Release Notes:

复制粘贴MVC4发行说明:

Modern HTTP programming model: Directly access and manipulate HTTP requests and responses in your Web APIs using a new, strongly typed HTTP object model. The same programming model and HTTP pipeline is symmetrically available on the client through the new HttpClient type.

•现代HTTP编程模型:使用新的强类型HTTP对象模型直接访问和操作Web api中的HTTP请求和响应。同样的编程模型和HTTP管道通过新的HttpClient类型在客户机上对称地可用。

Full support for routes: ASP.NET Web API supports the full set of route capabilities of ASP.NET Routing, including route parameters and constraints. Additionally, use simple conventions to map actions to HTTP methods.

•对路线的充分支持:ASP。NET Web API支持ASP的全套路由功能。NET路由,包括路由参数和约束。此外,使用简单的约定将操作映射到HTTP方法。

Content negotiation: The client and server can work together to determine the right format for data being returned from a web API. ASP.NET Web API provides default support for XML, JSON, and Form URL-encoded formats and you can extend this support by adding your own formatters, or even replace the default content negotiation strategy.

•内容协商:客户端和服务器可以共同确定从web API返回的数据的正确格式。ASP。NET Web API为XML、JSON和形式url编码格式提供了默认支持,您可以通过添加自己的格式器来扩展这种支持,甚至可以替换默认的内容协商策略。

Model binding and validation: Model binders provide an easy way to extract data from various parts of an HTTP request and convert those message parts into .NET objects which can be used by the Web API actions. Validation is also performed on action parameters based on data annotations.

•模型绑定和验证:模型绑定提供了一种简单的方法,可以从HTTP请求的各个部分提取数据,并将这些消息部分转换为. net对象,Web API操作可以使用这些对象。还根据数据注释对操作参数进行验证。

Filters: ASP.NET Web API supports filters including well-known filters such as the [Authorize] attribute. You can author and plug in your own filters for actions, authorization and exception handling.

•过滤器:ASP。NET Web API支持过滤器,包括众所周知的过滤器,如[Authorize]属性。您可以为操作、授权和异常处理创建并插入您自己的过滤器。

Query composition: Use the [Queryable] filter attribute on an action that returns IQueryable to enable support for querying your web API via the OData query conventions.

•查询组合:在返回IQueryable的操作上使用[Queryable]筛选属性,以支持通过OData查询约定查询web API。

Improved testability: Rather than setting HTTP details in static context objects, web API actions work with instances of HttpRequestMessage and HttpResponseMessage. Create a unit test project along with your Web API project to get started quickly writing unit tests for your Web API functionality.

•改进可测试性:web API操作与HTTP prequestmessage和HttpResponseMessage的实例一起工作,而不是在静态上下文对象中设置HTTP细节。与Web API项目一起创建一个单元测试项目,以快速开始为Web API功能编写单元测试。

Code-based configuration: ASP.NET Web API configuration is accomplished solely through code, leaving your config files clean. Use the provide service locator pattern to configure extensibility points.

•基于代码配置:ASP。NET Web API配置仅通过代码完成,使配置文件保持干净。使用“提供服务定位器”模式配置可扩展性点。

Improved support for Inversion of Control (IoC) containers: ASP.NET Web API provides great support for IoC containers through an improved dependency resolver abstraction

改进了对控制反转(IoC)容器的支持:ASP。NET Web API通过改进的依赖解析器抽象为IoC容器提供了很好的支持

Self-host: Web APIs can be hosted in your own process in addition to IIS while still using the full power of routes and other features of Web API.

•自宿主:除了IIS之外,Web API还可以托管在您自己的进程中,同时仍然充分利用路由和Web API的其他特性。

Create custom help and test pages: You now can easily build custom help and test pages for your web APIs by using the new IApiExplorer service to get a complete runtime description of your web APIs.

•创建自定义帮助和测试页面:现在您可以通过使用新的IApiExplorer服务来获得web api的完整运行时描述,从而轻松地为您的web api构建定制的帮助和测试页面。

Monitoring and diagnostics: ASP.NET Web API now provides light weight tracing infrastructure that makes it easy to integrate with existing logging solutions such as System.Diagnostics, ETW and third party logging frameworks. You can enable tracing by providing an ITraceWriter implementation and adding it to your web API configuration.

•监控和诊断:ASP。NET Web API现在提供了轻量级的跟踪基础设施,使得与现有的日志记录解决方案(如System)集成变得很容易。诊断、ETW和第三方日志记录框架。可以通过提供ITraceWriter实现并将其添加到web API配置来启用跟踪。

Link generation: Use the ASP.NET Web API UrlHelper to generate links to related resources in the same application.

•链接生成:使用ASP。NET Web API UrlHelper在同一个应用程序中生成与相关资源的链接。

Web API project template: Select the new Web API project form the New MVC 4 Project wizard to quickly get up and running with ASP.NET Web API.

•Web API项目模板:从新的MVC 4项目向导中选择新的Web API项目,使用ASP快速启动和运行。净Web API。

Scaffolding: Use the Add Controller dialog to quickly scaffold a web API controller based on an Entity Framework based model type.

•搭建:使用Add Controller对话框快速搭建基于实体框架模型类型的web API控制器。

#2


42  

Copy and paste from Whats new in MVC4 - MVC3 Vs MVC4

从MVC4 - MVC3和MVC4中复制粘贴新的内容

Whats new in MVC4 - MVC3 Vs MVC4

MVC4 - MVC3和MVC4有什么新东西

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

用于创建新的ASP的模板。NET MVC 4项目已经更新,以创建一个更加现代的网站。

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

如果您正在启动一个新项目,并希望为移动和平板浏览器创建一个站点,那么您可以使用新的移动应用程序项目模板。这是基于jQuery Mobile,一个用于构建触摸优化UI的开源库

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\Home\Index.cshtml template. If a mobile browser requests the Home page, the application might return the Views\Home\Index.mobile.cshtml template.

新的显示模式特性允许应用程序根据发出请求的浏览器选择视图。例如,如果桌面浏览器请求主页,应用程序可能会使用view \Home\Index。cshtml模板。如果移动浏览器请求主页,应用程序可能会返回视图\Home\Index.mobile。cshtml模板。

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

jQuery Mobile, the View Switcher, and Browser Overriding

jQuery Mobile、视图切换器和浏览器覆盖

jQuery Mobile is an open source library for building touch-optimized web UI. If you want to use jQuery Mobile with an ASP.NET MVC 4 application, you can download and install a NuGet package that helps you get started. To install it from the Visual Studio Package Manager Console, type the following command: Install-Package jQuery.Mobile.MVC This installs jQuery Mobile and some helper files, including the following: Views/Shared/Layout.Mobile.cshtml, which is a jQuery Mobile-based layout. A view-switcher component, which consists of the Views/Shared/ViewSwitcher.cshtml partial view and the ViewSwitcherController.cs controller. After you install the package, run your application using a mobile browser (or equivalent, like the Firefox User Agent Switcher add-on). You'll see that your pages look quite different, because jQuery Mobile handles layout and styling. To take advantage of this, you can do the following If visitors click the link, they’re switched to the desktop version of the same page. Because your desktop layout will not include a view switcher by default, visitors won't have a way to get to mobile mode. To enable this, add the following reference to _ViewSwitcher to your desktop layout, just inside the element:

jQuery Mobile是一个用于构建触摸优化的web UI的开源库。如果你想要使用jQuery手机和ASP。NET MVC 4应用程序,您可以下载并安装一个NuGet包,帮助您入门。要从Visual Studio包管理器控制台安装它,请输入以下命令:install -Package jQuery.Mobile。MVC安装jQuery Mobile和一些帮助文件,包括:view /Shared/Layout.Mobile。cshtml是一个基于jQuery移动的布局。一个视图切换组件,它由视图/共享/视图切换器组成。cshtml部分视图和ViewSwitcherController。cs控制器。安装完包后,使用移动浏览器(或类似的浏览器,如Firefox用户代理切换插件)运行应用程序。您将看到您的页面看起来非常不同,因为jQuery Mobile处理布局和样式。为了利用这个优势,如果访问者点击链接,他们就会切换到相同页面的桌面版本。由于您的桌面布局在默认情况下不包含视图切换器,访问者将无法进入移动模式。要实现这一点,将_ViewSwitcher以下引用添加到您的桌面布局中,就在元素内部:

@Html.Partial("_ViewSwitcher")

... Browser Overriding is a core feature of ASP.NET MVC 4 and is available even if you don't install the jQuery.Mobile.MVC package. However, it affects only view, layout, and partial-view selection — it does not affect any other ASP.NET feature that depends on the Request.Browser object.

…浏览器覆盖是ASP的一个核心特性。NET MVC 4,即使您不安装jQuery.Mobile,也可以使用。MVC包。但是,它只影响视图、布局和部分视图选择——它不影响任何其他ASP。取决于请求的NET特性。浏览器对象。

Recipes for Code Generation in Visual Studio

在Visual Studio中生成代码的方法。

The new Recipes feature enables Visual Studio to generate solution-specific code based on packages that you can install using NuGet. The Recipes framework makes it easy for developers to write code-generation plugins, 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 easily be checked into source control and shared with all developers on the project automatically. They are also available on a per-solution basis.

新的菜谱特性使Visual Studio能够基于您可以使用NuGet安装的包生成特定于解决方案的代码。recipe框架使开发人员很容易编写代码生成插件,您还可以使用这些插件替换用于添加区域、添加控制器和添加视图的内置代码生成器。由于菜谱是作为NuGet包部署的,因此可以很容易地将它们检入源代码控制并与项目中的所有开发人员自动共享。它们也可以在每个解决方案的基础上使用。

Task Support for Asynchronous Controllers

异步控制器的任务支持

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

现在,您可以将异步操作方法作为返回类型任务或任务的对象的单一方法来编写。

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

例如,如果您正在使用Visual c# 5(或使用Async CTP),您可以创建一个类似于以下内容的异步操作方法:

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, the calls to newsService.GetHeadlinesAsync and sportsService.GetScoresAsync are called asynchronously and do not block a thread from the thread pool.

在前面的操作方法中,调用newsService。GetHeadlinesAsync sportsService。GetScoresAsync是异步调用的,不会阻塞线程池中的线程。

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

返回任务实例的异步操作方法也可以支持超时。为了使您的操作方法可以被取消,在动作方法签名中添加一个类型取消令牌参数。下面的示例展示了一个异步操作方法,它的超时为2500毫秒,如果发生超时,它将向客户端显示TimedOut视图。

[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

希望这个有帮助。谢谢

#3


2  

Please go through the URL for all MVC 4 new features

请查看所有MVC 4的新特性的URL

#4


1  

MVC 3

MVC 3

  1. Integrated Scaffolding system extensible via NuGet
  2. 通过NuGet可扩展的集成脚手架系统。
  3. HTML 5 enabled project templates
  4. 支持HTML 5的项目模板
  5. Expressive Views including the new Razor View Engine
  6. 表达视图,包括新的Razor视图引擎。
  7. Powerful hooks with Dependency Injection and Global Action Filters
  8. 具有依赖注入和全局操作过滤器的强大钩子
  9. Rich JavaScript support with unobtrusive JavaScript, jQuery Validation, and JSON binding
  10. 丰富的JavaScript支持,不引人注目的JavaScript、jQuery验证和JSON绑定

MVC 4

MVC 4

  1. ASP.NET Web API
  2. ASP。净Web API
  3. Refreshed and modernized default project templates
  4. 更新和现代化的默认项目模板
  5. New mobile project template
  6. 新的移动项目模板
  7. Many new features to support mobile apps
  8. 许多新功能支持移动应用。
  9. Enhanced support for asynchronous methods
  10. 增强对异步方法的支持。

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

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

#5


0  

Please check the below links to find out the differences.

请查看下面的链接以了解差异。

http://forums.asp.net/t/1753017.aspx

http://forums.asp.net/t/1753017.aspx

http://www.askamoeba.com/Answer/130/Whats-new-in-MVC4-MVC3-Vs-MVC4

http://www.askamoeba.com/Answer/130/Whats-new-in-MVC4-MVC3-Vs-MVC4

http://forums.asp.net/t/1918539.aspx?Main+difference+between+regular+webapplication+mvc3+and+mvc4+

http://forums.asp.net/t/1918539.aspx?Main + +差+常规+ webapplication + mvc3 +和+ mvc4 +

#6


0  

One of the important feature introduced in MVC 4.0 was of Asynchronous controllers which enables to write the asynchronous action methods. Asynchronous controller allows an operation to get performed without making the working thread idle.

MVC 4.0引入的一个重要特性是异步控制器,它允许编写异步操作方法。异步控制器允许在不使工作线程空闲的情况下执行操作。

When an asynchronous action is invoked, the following steps occur:

当调用异步操作时,发生以下步骤:

The Web server gets a thread from the thread pool (the worker thread) and schedules it to handle an incoming request. This worker thread initiates an asynchronous operation. The worker thread is returned to the thread pool to service another Web request. When the asynchronous operation is complete, it notifies ASP.NET. The Web server gets a worker thread from the thread pool (which might be a different thread from the thread that started the asynchronous operation) to process the remainder of the request, including rendering the response.

Web服务器从线程池(工作线程)获取一个线程,并安排它处理传入的请求。这个工作线程启动一个异步操作。工作线程被返回到线程池以服务另一个Web请求。当异步操作完成时,它会通知ASP.NET。Web服务器从线程池(可能是与启动异步操作的线程不同的线程)获取工作线程,以处理请求的其余部分,包括呈现响应。

Converting Synchronous Action Methods to Asynchronous Action Methods

将同步操作方法转换为异步操作方法。

Following is the example of synchronous action method and the its asynchronous equivalent version.

下面是同步操作方法及其异步等效版本的示例。

Synchronous Controller:

同步控制器:

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

Asynchronous variant of above operation:

以上操作的异步变体:

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

  public ActionResult IndexCompleted()
  {
   return View();
  }
}

Steps:

步骤:

  • Synchronous Controllers are the classes derived from the Controller class to implement an AsyncController instead of deriving the controller from Controller, derive it from AsyncController class. Controllers that derive from AsyncController enable ASP.NET to process asynchronous requests, and they can still service synchronous action methods.

    同步控制器是从控制器类派生的类来实现异步控制器,而不是从控制器派生控制器,从异步控制器类派生控制器。从异步控制器派生的控制器支持ASP。NET处理异步请求,它们仍然可以服务同步操作方法。

  • Corresponding to the synchronous action method in Synchronous controller you need to create two methods for the action in asynchronous controller.First method that initiates the asynchronous process must have a name that consists of the action and the suffix "Async". The other method that is invoked when the asynchronous process finishes (the callback method) must have a name that consists of the action and the suffix "Completed".

    与同步控制器中的同步操作方法对应,需要为异步控制器中的操作创建两个方法。初始化异步进程的第一个方法必须有一个由动作和后缀“Async”组成的名称。当异步进程完成(回调方法)时调用的另一个方法必须有一个由动作和后缀“完成”组成的名称。

    In the above sample example, the Index action has been turned into two methods in asynchronous controller: IndexAsync and IndexCompleted.

    在上面的示例示例中,索引操作被转换为异步控制器中的两种方法:IndexAsync和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 for a synchronous action method (for example, Controller/Index).

    IndexAsync方法返回void,而indexcomplete方法返回一个ActionResult实例。尽管该操作由两种方法组成,但它使用与同步操作方法(例如,控制器/索引)相同的URL访问。

Note the following about asynchronous action methods:

注意以下关于异步操作方法的内容:

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

如果操作名是Sample,框架将查找SampleAsync和SampleCompleted方法。

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

视图页面应该命名为Sample。aspx而不是SampleAsync。aspx或SampleCompleted.aspx。(动作名是Sample,不是SampleAsync)

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

控制器不能包含名为SampleAsync的异步方法和名为Sample的同步方法。如果是,则抛出一个歧义匹配异常,因为SampleAsync操作方法和示例操作方法具有相同的请求签名。

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

有关更多细节,请点击这里:http://www.consullingbyabhi.com/2014/05/asynchronous -controllers in-aspnet-mvc.html