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. hadoop 有那些发行版本

    hadoop发行版本 1. apache hadoop  http://hadoop.apache.org/ 2. cloudera hadoop(CDH) https://www.cloudera. ...

  2. python基本数据类型之集合

    python基本数据类型之集合 集合是一种容器,用来存放不同元素. 集合有3大特点: 集合的元素必须是不可变类型(字符串.数字.元组): 集合中的元素不能重复: 集合是无序的. 在集合中直接存入lis ...

  3. 14.2.4HTML5约束API验证

    <body> <form> <!-- required属性在提交表单时不能空着 这个属性适用于<input> <textarea> <sel ...

  4. 23.HashMap

    HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以key-value的形式存在.在HashMap中,key-value总是会当做一个整体来处理,系统会根据 ...

  5. Ngui使用随心记

    Ngui的一些基础使用心得! BB:首先BB一下我觉得NGUI和UGUI哪个好?我首推UGUI,先不说是官方内置,在使用的方便性上也要好很多,而且NGUI停止更新了!还有就是NGUI有BUG! Ngu ...

  6. Shell 中字符串变量的赋值注意点

    1. 变量赋值 语法:var="saaaa" PS: 等号两边不能有空格 2. 脚本示例如下: #!/bin/sh # Get bug activity info # usage ...

  7. B树之C语言实现(包含查找、删除、插入)

    B树的定义 一棵m阶B树(Balanced Tree of order m),或为空树,或为满足下列特性对的m叉树. 树中每个结点最多含有m棵子树. 若根结点不是叶子结点,则至少有2个子树. 除根结点 ...

  8. [UWP]不那么好用的ContentDialog

    ContentDialog是UWP开发中最常用的组件之一,一个体验良好的UWP应用很难避免不去使用它.博客园里也有许多的文章介绍如何来利用ContentDialog实现各种自定义样式的弹窗界面.不过实 ...

  9. Increasing Subsequence (hard version)

    首先讲一下题目大意:给你n个数,然后从最左边(L)或者最右边(R)取一个数生成出一个新的序列,对于这个序列的要求是递增的(注意是递增的,不能存在等于的情况)问这个序列有多长.并打印此操作. 这题就是忘 ...

  10. SpringCloud总结

    初级入门使用轮廓,整理一下思路