ActionResult 返回类型
来源:互联网 发布:ubuntu 释放内存 编辑:程序博客网 时间:2024/06/06 03:17
MVC3中Action返回类型ActionResult在System.Web.Mvc命名空间中.这些包含在控制器中的方法,我们称为控制器中的 Action,比如:HomeController 中的 Index 方法就是一个 Action,这些 Action 的作用就是处理请求,然后返回对请求的处理结果。
ActionResult是一个抽象类, 在Action中返回的都是其派生类.下面是我整理的ASP.NET MVC 1.0 版本中提供的ActionResult派生类:
类名抽象类父类功能ContentResult重写了父类的FindView方法.
寻找用户控件.ascx文件ViewResult
重写了父类的FindView方法.
寻找页面.aspx文件
view plainprint?
- public
class ActionResultController : Controller -
- {
-
- public
ActionResult Index() -
- {
-
- return
View(); -
- }
-
- public
ActionResult ContentResult() -
- {
-
- return
Content("Hi, 我是ContentResult结果"); -
- }
-
- public
ActionResult EmptyResult() -
- {
-
- //空结果当然是空白了!
-
- //至于你信不信,
我反正信了 -
- return
new EmptyResult(); -
- }
-
- public
ActionResult FileResult() -
- {
-
- var
imgPath = Server.MapPath("~/demo.jpg"); -
- return
File(imgPath, "application/x-jpg", "demo.jpg"); -
- }
-
- public
ActionResult HttpNotFoundResult() -
- {
-
- return
HttpNotFound("Page Not Found"); -
- }
-
- public
ActionResult HttpUnauthorizedResult() -
- {
-
- //未验证时,跳转到Logon
-
- return
new HttpUnauthorizedResult(); -
- }
-
- public
ActionResult JavaScriptResult() -
- {
-
- string
js = Hi,"alert(\" I'm JavaScript.\");"; -
- return
JavaScript(js); -
- }
-
- public
ActionResult JsonResult() -
- {
-
- var
jsonObj = new -
- {
-
- Id
= 1, -
- Name
= "小铭", -
- Sex
= "男", -
- Like
= "足球" -
- };
-
- return
Json(jsonObj, JsonRequestBehavior.AllowGet); -
- }
-
- public
ActionResult RedirectResult() -
- {
-
- return
Redirect("~/demo.jpg"); -
- }
-
- public
ActionResult RedirectToRouteResult() -
- {
-
- return
RedirectToRoute(new { -
- controller
= "Hello",action = "" -
- });
-
- }
-
- public
ActionResult ViewResult() -
- {
-
- return
View(); -
- }
-
- public
ActionResult PartialViewResult() -
- {
-
- return
PartialView(); -
- }
-
- //禁止直接访问的ChildAction
-
- [ChildActionOnly]
-
- public
ActionResult ChildAction() -
- {
-
- return
PartialView(); -
- }
-
- //正确使用ChildAction
-
- public
ActionResult UsingChildAction() -
- {
-
- return
View(); -
- }
-
- }
0 0
- ActionResult 返回类型
- MVC3 ActionResult 返回类型
- MVC 返回ActionResult 类型
- ActionResult 返回类型
- ActionResult 返回类型
- actionresult的返回类型
- .net 中 ActionResult 返回类型
- MVC3中Action返回类型ActionResult类型
- MVC(六、ActionResult 返回类型 )
- Asp.net MVC 中Controller返回值类型ActionResult
- Asp.net MVC 中Controller返回值类型ActionResult
- Asp.net MVC 中Controller返回值类型ActionResult
- Asp.net MVC 中Controller返回值类型ActionResult
- Asp.net MVC 中Controller返回值类型ActionResult
- Asp.net MVC 中Controller返回值类型ActionResult
- Asp.net MVC 中Controller返回值类型ActionResult
- Asp.net MVC 中Controller返回值类型ActionResult
- 关于asp.net mvc中Controller中的方法返回值类型ActionResult及其子类的理解
- 使用glide加载的图片在展示的时候是圆形
- 重构-改善既有代码的设计精华摘录
- HDU 2209 翻纸牌游戏 By Assassin 模拟
- 基础知识(字符串,数组,对象)
- intellij idea maven 配置使用
- ActionResult 返回类型
- Linux权限管理之文件默认权限
- JDK中sql包下DataSource接口源码
- ng2功能模块
- JNI学习笔记
- Spring学习历程---request,session与globalSession作用域
- android数据库SQLite
- SSH网站开发实录(4)(实现登录功能)SpringMVC+Spring+Hibernate
- 为Android频繁的网络请求设置本地缓存