actionresult的返回类型
来源:互联网 发布:边境牧羊犬多聪明 知乎 编辑:程序博客网 时间:2024/05/17 04:41
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的返回类型
- ActionResult 返回类型
- MVC3 ActionResult 返回类型
- MVC 返回ActionResult 类型
- ActionResult 返回类型
- ActionResult 返回类型
- .net 中 ActionResult 返回类型
- MVC3中Action返回类型ActionResult类型
- ActionResult的其它返回值
- ActionResult的其它返回值
- ActionResult的其它返回值
- MVC(六、ActionResult 返回类型 )
- 关于asp.net mvc中Controller中的方法返回值类型ActionResult及其子类的理解
- 5.ActionResult的其它返回值
- MVC Controller与ActionResult的返回值
- ActionResult返回Json时的exception
- Asp.net MVC 中Controller返回值类型ActionResult
- Asp.net MVC 中Controller返回值类型ActionResult
- 设计模式之中介者模式
- 二叉树
- [贪心][DP][Ural 1203]Scientific Conference
- JavaWeb中路径问题
- NYOJ 306 走迷宫(DFS+二分法)
- actionresult的返回类型
- ubuntu14.04环境下安装配置OpenCV3.2+anaconda2(Python2.7)
- 深入浅出搜索架构引擎、方案与细节(上)
- NYOJ 304 节能(DP)
- python学习1 详细记录python的range()函数用法
- [Codevs] 3044 矩形面积求并(离散化)
- 算法
- ubuntu校园网登陆客户端 mentohust下载安装
- 线段树练习题一