Result(ActionResult、JsonResult、JavaScriptResult等)
一丶ActionResult
应用于Action方法前面的类型,它是Action的返回值,代表Action的执行结果。
public ActionResult Index()
{
return View();
}
二丶JsonResult
返回Json字符串,但ajax接受到后,会自动转换成Json对象进行使用。
public ActionResult Val1()
{ //生成3个随机数
Random rd = new Random();
var a = rd.Next(, );
var b = rd.Next(, );
var c = rd.Next(, );
//申明一个匿名类
var msg = new
{
a1 = a,
a2 = b,
a3 = c,
};
return Json(msg);
}
三丶JavaScriptResult
通过后台返给前端js代码。
1 public ActionResult GetJs()
{
return JavaScript("alert('我是js代码,调用的是JavaScriptResult')");
}
public ActionResult GetJs2()
{
return Content("alert('我是js代码,调用的是ContentResult,并自定义的返回类型为js')", "application/x-javascript");
}
四丶FileResult
应用于下载文件
public FileResult DownLoadExcel(StudentInfo studentInfo, Student_Photo student_Photo, string dateStart, string dateEnd)
{
List<StuInfoAndImg> stuInfoAndImgList = GetStu_List(studentInfo, student_Photo, dateStart, dateEnd);
string pathFileName = string.Empty;
ExportStudentExcel(stuInfoAndImgList, out pathFileName);
string fileName = DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".xlsx"; return File(pathFileName, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName);
}
Result(ActionResult、JsonResult、JavaScriptResult等)的更多相关文章
- 第五节:从源码的角度理解各种Result(ActionResult、JsonResult、JavaScriptResult等)
一. 背景 提到MVC不得不说MVC中的各种Result,这些高度封装的xxxResult以及在xxxResult再度封装的xxx,大大提高了MVC框架的开发效率. 相信做过MVC开发的朋友都会用到过 ...
- MVC ActionResult JsonResult
以下是ActionResult的继承图: 大概的分类: EmptyResult:表示不执行任何操作的结果 ContentResult :返回文本结果 JavaScriptResult:返回结果为Jav ...
- 工作总结 页面 ActionResult / JsonResult 将对象以 Json() 返回
其实都不用在页面上序列化 打印 都不需要在页面上 像这样 var ajaxResult = eval("(" + data + ")"); 序列化为对象 ...
- CRUD全栈式编程架构之MVC的扩展设计
MVC执行流程 路由的扩展 我理解的路由作用有以下几个 Seo优化,用“/”分开的url爬虫更爱吃 物理和逻辑文件分离,url不再按照文件路径映射 Controller,Action的选择 MVC路由 ...
- 解析ActionResult子类JsonResult
前言 MVC我是11开始使用的,当时还是在上地软件园一小型互联网公司,当时是MVC2.0+Linq to sql.后来接着学习MVC3,MVC3的出现确实让我有种眼前一亮的感觉,期间我不断的写各种de ...
- 使用ExposedObject对Asp.net MVC中匿名类型的JsonResult做单元测试
返回JsonResult是MVC中的常见返回值类型,而且简单方便的方式是结合匿名类型一起使用. 比如: public ActionResult PreviewEmail() { …… return J ...
- ASP.NET MVC ActionResult的实现
1.11种ActionResult 在System.Web.Mvc命名空间下: ActionResult是一个抽象类, 在Action中返回的都是其派生类.下面是我整理的ASP.NET MVC 1.0 ...
- MVC3中Action返回类型ActionResult类型
MVC3中Action返回类型ActionResult在System.Web.Mvc命名空间中.这些包含在控制器中的方法,我们称为控制器中的 Action,比如:HomeController 中的 I ...
- 第三节:框架前期准备篇之利用Newtonsoft.Json改造MVC默认的JsonResult
一. 背景 在MVC框架中,我们可能经常会用到 return Json(),而Json方法内部又是一个JsonResult类,那么JsonResult内部又是什么原理呢?在MVC框架中,各种xxxRe ...
随机推荐
- 【POJ 1275】 Cashier Employment(差分约束系统的建立和求解)
[POJ 1275] Cashier Employment(差分约束系统的建立和求解) Cashier Employment Time Limit: 1000MS Memory Limit: 10 ...
- vim note(5)
.vimrc 的设置 $HOME/.vimrc 的普通设置,例如以下. set nocompatible "" not compatible with VI "" ...
- cocos2dx 纹理优化
description: 为什么要谈纹理的问题,游戏的画面无时无刻不充斥着图像,通俗意义上一款精致的游戏都有着非常精美的画面.这样往往能给玩家带来更好的游戏体验,这一点也是对于游戏制作者来说所尽力追求 ...
- 用block变量来对字符数组对象进行排序
<span style="font-size:18px;">降序排序</span> <span style="font-size:18px; ...
- UVA 11488 Hyper Prefix Sets (Trie)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 鸟哥的Linux私房菜-----9、vi文本处理器
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGVrZXdhbmd6aQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- Web框架 - 开源软件库 - 开源中国社区
网址:http://www.oschina.net/project/tag/127?lang=194
- [Codeforces 496E] Distributing Parts
[题目链接] https://codeforces.com/contest/496/problem/E [算法] 按右端点排序 , 每个乐曲优先选取的左端点最大的演奏家 用std :: set维护贪心 ...
- [转]使用git进行版本控制
使用git进行版本控制 本文将介绍一种强大的版本控制工具,git的基本使用.与之前svn工具类似,首先给出一些常见的使用需求,然后以这些需求为中心,来展开git的学习过程.由于我也是在学习当中所以其中 ...
- 常用开源<监控软件>介绍
转载地址:http://blog.csdn.net/lx_9986/article/details/6803243 一.Zenoss Core Zenoss Core是开源企业级IT管理软件-是智能监 ...