Web服务器接收到一个客户端请求以后,会对请求予以相应,而这个响应是通过Response来控制的,

但是在asp.net mvc 里,这部分的工作是由ActionResult来完成的,

ActionResult是一个抽象类,所以具体的工作还是由很多个子类来完成,

具体的子类有

EmptyResult,

ContentResult

(通过Content,ContentEncoding,ContentType 分别设置返回的内容,字符编码格式以及媒体类型),

FileResult(FileContentResult,FilePathResult,FileStreamResult),

<p>Use this area to provide additional information.</p>
<a href="@Url.Action("ImagePath1", new { id="1" })">下载</a> <img src="@Url.Action("ImagePath1", new { id="1" })" /> <img src="@Url.Action("ImagePath", new { id="1" })" /> <img src="@Url.Action("ImageContent", new { id="1" })" /> <img src="@Url.Action("ImageStream", new { id="1" })" />
        public ActionResult ImagePath(string id)
{
string path = Server.MapPath("/images/" + id + ".jpeg");
return File(path, "image/jpeg");
} public ActionResult ImagePath1(string id)
{
string path = Server.MapPath("/images/" + id + ".jpeg");
return File(path, "image/jpeg", "下载");
} public ActionResult ImageContent(string id)
{
string path = Server.MapPath("/images/" + id + ".jpeg");
byte[] heByte = null;
using (FileStream fsRead = new FileStream(path, FileMode.Open, FileAccess.Read))
{
int fsLen = (int)fsRead.Length;
heByte = new byte[fsLen];
int r = fsRead.Read(heByte, 0, heByte.Length);
}
return File(heByte, "image/jpeg");
}
public ActionResult ImageStream(string id)
{
string path = Server.MapPath("/images/" + id + ".jpeg");
FileStream fsRead = new FileStream(path, FileMode.Open, FileAccess.Read); return File(fsRead, "image/jpeg"); }

JavaScriptResult,

返回一段js,且媒体类型是application/x-javascript,

JsonResult,

返回Json数据,默认ContentType为Application/json.

HttpStatusCodeResult,

具体是通过设置response的StatusCode和StatusDescription来完成输出

RedirectResult,RedirectToRouteResult,

内部是通过Response的Redirect/RedirectPermanent来完成操作,

redirectresult具有两个属性permanent和URL,URL可以是绝对的地址也可以是相对地址,permanent决定了重定向是暂时的还是永久的重定向,

两种重定向的不同点事搜索引擎会根据永久重定向来更新自己的索引,

RedirectToRouteResult较RediretResult多了一步根据路由计算出来这个URL值,

所以RedirectToRouteResult没有URL属性,却包含RouteName以及RouteValues属性,

ViewResult.

ViewResult是一个特殊的ActionResult,但也是最复杂的一个

asp.net mvc之ActionResult的更多相关文章

  1. [转载]深入理解ASP.NET MVC之ActionResult

    Action全局观 在上一篇最后,我们进行到了Action调用的“门口”: 1 if (!ActionInvoker.InvokeAction(ControllerContext, actionNam ...

  2. Asp.net MVC 之 ActionResult

    Action运行完后,回传的值通过ActionResult 类别或者其衍生的类别操作.ActionResult是一个抽象类,因此,Asp.net MVC 本身就实作了许多不同类型的ActionResu ...

  3. ASP.NET MVC自定义ActionResult实现文件压缩

    有时候需要将单个或多个文件进行压缩打包后在进行下载,这里我自定义了一个ActionResult,方便进行文件下载 using System; using System.Collections; usi ...

  4. ASP.NET MVC 拓展ActionResult实现Html To Pdf 导出

    之前实现了html直接转换为word文档的功能,那么是否也同样可以直接转换为pdf文档呢,网上搜了下html to pdf 的开源插件有很多 如:wkhtmltopdf,pdfsharp,itexts ...

  5. ASP.NET MVC 中 ActionResult 和 ViewResult 在使用上的区别

    如果确认你返回的是一个视图(view),你可以直接返回类型为ViewResult. 如果你并不是很清楚,或者你根本不想去理解这些东西,你可以直接返回ActionResult

  6. Asp.net MVC 控制器ActionResult的例子

    ActionResult 父类型 ViewResult View() 多重载应用 PartialViewResult PartialView() 部分试图 New EmptyResult()  空 如 ...

  7. Asp.net MVC 之ActionResult

    ActionResult 派生出以下子类: ViewResult 返回一个网页视图 PartialViewResult 返回一个网页视图,但不适用布局页. ContentResult 返回一段字符串文 ...

  8. ASP.NET MVC中ActionResult的不同返回方式

    1.返回视图 return View();//返回方法名对应的视图 return View("aaa");//返回名称为aaa的视图 2.返回文本内容 return Content ...

  9. 【转】ASP.NET MVC学习笔记-Controller的ActionResult

    1. 返回ViewResult public ActionResult Index()   {       ViewData["Message"] = "Welcome ...

随机推荐

  1. POJ2455 Secret Milking Machine

    Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12324   Accepted ...

  2. freeRTOSConfig.h文件对FreeRTOS进行系统配置

    FreeRTOS内核是高度可定制的,使用配置文件FreeRTOSConfig.h进行定制.每个FreeRTOS应用都必须包含这个头文件,用户根据实际应用来裁剪定制FreeRTOS内核.这个配置文件是针 ...

  3. 嵌入式ROM核的调用

    本次设计的工具和源码在:http://download.csdn.net/detail/noticeable/9914766 课程目的:调用quartus II提供的rom(read only mem ...

  4. [smf]论坛实现编辑器附件插入的插件

    smf论坛代码的相关介绍,可以参见博客园的其他文章,这里不再详细说明了. 插件功能: 在帖子里的任何位置插入附件图片. 关于安装: 该插件已经经过“维尼熊的百宝箱”的修改,在新版本SMF 2.0.14 ...

  5. 统计C/C++代码行数

    近日在写一个统计项目中C/C++文件(后缀名:C/CPP/CC/H/HPP文件)代码行数的小程序.给定包含C/C++代码的目录,统计目录里所有C/C++文件的总代码行数.有效代码行数.注释行数.空白行 ...

  6. JavaSE核心之一:Date类、Calendar类、Math类、枚举;

    1.Date类 1) java.util.Date类用于封装日期及时间信息,一般仅用它显示某个日期,不对他作任何操作处理,作处理用Calendar类,计算方便. 2) Date 类本质上拥有一个lon ...

  7. Flask 中内置的 Session

    Flask中的Session Flask中的Session不同于Django的session,django的session存在后端数据库中,而flask的session会将你的SessionID存放在 ...

  8. PHP 生成验证码(+图片没有显示的解决办法)

    今天有需要用到验证码,就敲了个,毕竟用途比较广,所以打算把代码留下来,以后肯定用得上的.当然,今天在做的时候也是有一些问题的,分享出来吧,记录自己所犯的错误,避免以后再掉坑里. 先给个效果图(下面的真 ...

  9. 9.indicate、xutils、json

    json数据  页签详情页数据   public class TabData { public int retcode; public TabDetail data;//不是数组的话类型就是这个 pu ...

  10. Spring Boot Runner启动器

    Runner启动器 如果你想在Spring Boot启动的时候运行一些特定的代码,你可以实现接口ApplicationRunner或者CommandLineRunner,这两个接口实现方式一样,它们都 ...