第12章 控制器与动作 — 精通 MVC 3 框架

Controllers and Actions
控制器与动作

Every request that comes to your application is handled by a controller. The controller is free to handle the request any way it sees fit, as long as it doesn’t stray into the areas of responsibility that belong to the model and view. This means that we don’t put business or data storage logic into a controller, nor do we generate user interfaces.
到达你应用程序的每一个请求都是由控制器处理的。控制器可以以它认为合适的方式自由地处理请求,只要它不偏离到属于模型和视图职责的领域。意即,我们不要把事务或数据存储逻辑放到控制器中来,也不要生成用户界面

In the ASP.NET MVC Framework, controllers are .NET classes that contain the logic required to handle a request. In Chapter 4, we explained that the role of the controller is to encapsulate your application logic. This means that controllers are responsible for processing incoming requests, performing operations on the domain model, and selecting views to render to the user.
在ASP.NET MVC框架中,控制器是.NET类,它含有处理请求所需要的逻辑。在第4章中我们解释过,控制器的作用是封装应用程序逻辑。这意味着控制器要负责处理输入请求、执行域模型上的操作、并选择渲染给用户的视图。

In this chapter, we will show you how controllers are implemented and the different ways that you can use controllers to receive and generate output. The MVC Framework doesn’t limit you to generating HTML through views, and we’ll discuss the other options that are available. We will also show how action methods make unit testing easy and demonstrate how to test each kind of result that an action method can produce.
在本章,我们将向你演示控制器是如何实现的,以及你能够把控制器用来接收并生成输出的不同方法。MVC框架并未限制你只有通过视图才可以生成HTML,而且我们也将讨论其它可用的选择。我们也将演示动作方法如何使单元测试容易,并演示如何测试一个动作方法能够产生的各种结果。

posted on 2012-06-13 20:55  lucky.net  阅读(126)  评论(0编辑  收藏  举报

导航

Copyright luckynet 2013