在System.Web.Mvc命名空间 ActionResult ContentResult EmptyResult FileResult HttpStatusCodeResult HttpNotFoundResult HttpUnauthorizedResult JavaScriptResult JsonResult RedirectResult RedirectToRouteResult ViewResultBase PartialViewResult

ViewResult

示例代码:

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 = "alert(\"Hi, 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();

}

}

ASP.NET MVC3默认提供了11种ActionResult的实现的更多相关文章

  1. 聊聊ASP.NET Core默认提供的这个跨平台的服务器——KestrelServer

    跨平台是ASP.NET Core一个显著的特性,而KestrelServer是目前微软推出了唯一一个能够真正跨平台的Server.KestrelServer利用一个名为KestrelEngine的网络 ...

  2. 经典ASP.NET MVC3.0入门详解

    http://blog.csdn.net/csh624366188/article/details/7064269 :由于本文原在word文档里编写,写本文章时运用了大量截图,直接复制到博客里,没有显 ...

  3. ASP.NET MVC3 系列教程 - Razor视图引擎基础语法

    http://www.cnblogs.com/highend/archive/2011/04/09/aspnet_mvc3_razor_engine.html 4. 关于所有带"_" ...

  4. ASP.NET MVC3快速入门——第五节、从控制器访问模型中的数据

    5.1 从控制器访问模型中的数据在本节中,我们将创建一个新的MoviesController类,并且书写代码来获取数据库中的数据,并通过视图模板来显示在浏览器中.鼠标右击Controller文件夹,点 ...

  5. 实现Android操作系统11种传感器介绍

    在Android2.3 gingerbread系统中,google提供了11种传感器供应用层使用. #define SENSOR_TYPE_ACCELEROMETER 1 //加速度 #define ...

  6. ASP.NET MVC3 入门指南之数据验证[源码RAR下载]

    http://www.cnblogs.com/BingoLee/archive/2011/12/23/2298822.html 前言: 无论你编写什么样的网页程序,都需要对用户的数据进行验证,以确数据 ...

  7. Android操作系统中11种传感器的介绍【转】

    本文转载自:http://www.oschina.net/question/163910_28354 在Android2.3 gingerbread系统中,google提供了11种传感器供应用层使用. ...

  8. Java默认提供的线程池

    Java的线程池都是通过ThreadPoolExecutor来构建. public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, ...

  9. .NET开发人员必看:提高ASP.NET Web应用性能的24种方法和技巧

    那性能问题到底该如何解决?以下是应用系统发布前,作为 .NET 开发人员需要检查的点. 1.debug=「false」 当创建 ASP.NET Web应用程序,默认设置为「true」.开发过程中,设置 ...

随机推荐

  1. 【android】移植IOS视图响应陀螺仪交互行为

    IOS有个很有趣味的特性:背景图片可以响应陀螺仪方向的变化,去改变X.Y轴上的值,从而让整个界面看着充满着灵性.具体步骤是:解锁苹果产品,在IOS7以上,摆动手势,观察桌面背景图片的变化. 刚好,我们 ...

  2. android,结合Timer和TimerTask实现定时任务

    当我们需要每隔一段时间执行一个任务的时候,就需要使用TimerTask了,下面是入门的例子, 值得注意的是Timer.TimerTask,cancel之后就需要重新声明一个对象,否则会报错的哦~ pa ...

  3. Entity Framework Code First级联删除(转)

    使用Data Annotations: 如果我们要到一对主从表增加级联删除,则要在主表中的引用属性上增加Required关键字,如: public class Destination { public ...

  4. EF Code First 学习笔记:约定配置(转)

      要更改EF中的默认配置有两个方法,一个是用Data Annotations(在命名空间System.ComponentModel.DataAnnotations;),直接作用于类的属性上面;还有一 ...

  5. ubuntu下 adb devices找不到devices

    不同手机用数据线与ubuntu连接后,执行adb devices,好多出现找不到devices的情况. 这里解决措施: 1. 执行lsusb(连接手机前与后) 找到显示内容的差异项: root@loc ...

  6. 简单了解下CGI、FastCGI和php-fpm的概念和区别和运行原理

    什么是CGI? CGI(Common Gateway Interface),公共网关接口,它是Web服务器与外部应用程序(CGI程序)之间传递信息的接口标准.通过CGI接口,Web服务器就能够获取客户 ...

  7. RANSAC算法在图像拼接上的应用的实现

    关于算法原理请参考<基于SURF特征的图像与视频拼接技术的研究>. 一.问题提出         RANSAC的算法原理并不复杂,比较复杂的地方在于"建立模型"和&qu ...

  8. hdu 6430 线段树 暴力维护

    Problem E. TeaTree Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  9. luogu p1219 八皇后

    https://www.luogu.org/problem/show?pid=1219 经典问题,搜索一遍过. 重点是判断皇后能否在map[x][y]放下的条件 因为是dfs的时候过程中 x 是递增的 ...

  10. Gym 101246D Fire in the Country(dfs求SG函数)

    http://codeforces.com/gym/101246/problem/D 题意: 给定一个无向有环图,大火从1点开始,每个时间点与它相邻的点也将会着火,现在有两个人轮流操作机器人,机器人从 ...