Controller & Action
Controller 的要求
- 继承 System.Web.Mvc.Controller 类库
- 以 Controller 结尾
- XyzController 的名称即为 Xyz 约定胜于配置
- Asp.NET MVC 框架会在 Web 应用程序所引用的所有程序集范围内查找 Controller
Action 的要求
- 必须是一个方法
- 必须返回 ActionResult 类型
- 必须是实例方法
- 不能使泛型方法
- 没有标注 NonActionAttribute
- 不能被重载
Action 的选择规则
- 根据 URL Routing 提取后的数据进行选择
- 如果没有指定 Action 那么执行标注了 NonActionAttribute 的 ”Action”
- 如果指定了一个不存在的 Action, 或者没有指定 Action 并且 Controller 中没有标注 NonActionAttribute 的 ”Action” ,则调用 Controller 的 HandleUnknownAction 方法。
---- 默认抛出异常
---- 可覆盖( override )
ActionResult
- 一个抽象类,表示 Aciton 的执行结果
- ASP.NET MVC 框架将在获得 ActionResult 之后执行其 Execute 方法。
各种 ActionResult
- RedirectToAction
- View
- RedirectToRoute
- Redirect
1485

被折叠的 条评论
为什么被折叠?



