asp.net mvc返回文件:

public ActionResult ExportReflection(string accessToken)
{
var reflections = GetCmsReflectionList(accessToken); var sb = new StringBuilder();
sb.AppendFormat("{0,-10},{1,-10},{2,-10},{3,-10},{4,-10},{5,-100},{6,-100},{7,-50}", "创建者身份", "创建者姓名", "教练打分", "所属能力", "主题", "内容", "参与者", "创建时间");
sb.AppendLine();
foreach (var r in reflections)
{
var creatorRole = r.CreatorRole == ?"学员":"教练";
sb.AppendFormat("{0,-10},{1,-10},{2,-10},{3,-10},{4,-10},{5,-100},{6,-100},{7,-50}",
creatorRole,
r.CreatorUserName,
r.ScoreFromCoach,
r.CompetencyName,
r.Subject,
r.Content,
r.ParticipantsNameString,
r.CreatedTime);
sb.AppendLine();
}
//var encoding = Encoding.GetEncoding(936); //gb2312
var bytes = Encoding.GetEncoding().GetBytes(sb.ToString()); //return File(new MemoryStream(bytes, 0, bytes.Length), "application/csv", "reflections" + DateTime.UtcNow.ToShortDateString() + ".csv");//excel打开csv有乱码
return File(bytes, "application/csv", "reflections" + DateTime.UtcNow.ToShortDateString() + ".csv");
}

asp.net mvc return file result的更多相关文章

  1. Asp.net mvc 3 file uploads using the fileapi

    Asp.net mvc 3 file uploads using the fileapi I was recently given the task of adding upload progress ...

  2. ASP.Net MVC upload file with record & validation - Step 6

    Uploading file with other model data, validate model & file before uploading by using DataAnnota ...

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

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

  4. ASP.NET MVC – 关于Action返回结果类型的事儿(上)

    原文:ASP.NET MVC – 关于Action返回结果类型的事儿(上) 本文转自:博客园-文超的技术博客 一.         ASP.NET MVC 1.0 Result 几何? Action的 ...

  5. ASP.NET MVC中的拦截器

    在ASP.NET MVC中,有三种拦截器:Action拦截器.Result拦截器和Exception拦截器, 所谓的拦截器也没有什么的,只是写一个类,继承另一个类和一个接口,顺便实现接口里面的方法而以 ...

  6. ASP.NET没有魔法——ASP.NET MVC 过滤器(Filter)

    上一篇文章介绍了使用Authorize特性实现了ASP.NET MVC中针对Controller或者Action的授权功能,实际上这个特性是MVC功能的一部分,被称为过滤器(Filter),它是一种面 ...

  7. Mixing ASP.NET Webforms and ASP.NET MVC

    https://www.packtpub.com/books/content/mixing-aspnet-webforms-and-aspnet-mvc *********************** ...

  8. ASP.Net MVC Filter验证用户登录

    一.Filter是什么 ASP.NetMVC模式自带的过滤器Filter,是一种声明式编程方式,支持四种过滤器类型,各自是:Authorization(授权),Action(行为),Result(结果 ...

  9. 第2章 ASP.NET MVC(URL、路由及区域)

    * { font: 17px/1.5em "Microsoft YaHei" } ASPNET MVC URL.路由及区域 一.URL.路由及区域 一.      配置路由器 1. ...

随机推荐

  1. Oauth2.0认证---授权码模式

    目录: 1.功能描述 2.客户端的授权模式 3.授权模式认证流程 4.代码实现 1.功能描述 OAuth在"客户端"与"服务提供商"之间,设置了一个授权层(au ...

  2. ruby 生成有条件限制的随机数

    #conding:utf-8 #生成只有数字的随机码可控制长度def random_int(len) newpass = "" 1.upto(len){ |i| newpass & ...

  3. <<Differential Geometry of Curves and Surfaces>>笔记

    <Differential Geometry of Curves and Surfaces> by Manfredo P. do Carmo real line Rinterval I== ...

  4. 每天一个 Linux 命令(22):find 命令的参数详解

    find一些常用参数的一些常用实例和一些具体用法和注意事项. 1.使用name选项: 文件名选项是find命令最常用的选项,要么单独使用该选项,要么和其他选项一起使用.  可以使用某种文件名模式来匹配 ...

  5. Round() 四舍五入 js银行家算法(转)

    首先问一下round(0.825,2) 返回的结果,大家猜一猜, 首先SQL server 返回的是 0.83 js的返回结果 是0.83,code 如下: var b = 0.825;        ...

  6. soap发送报文请求和dom4j解析XML并且获得指定名称的节点信息

    package com.lzw.b2b.soap; import java.io.ByteArrayInputStream;import java.io.InputStream;import java ...

  7. 【转】easyui $.message.alert 点击右上角的关闭按钮时,不执行定义的回调函数

    今天發現這個問題 easyui  $.message.alert  点击右上角的关闭按钮时,不执行定义的回调函数

  8. 72. Generate Parentheses && Valid Parentheses

    Generate Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', ...

  9. petapoco存储过程

    db.ExecuteScalar<string>("exec P_GetCode @0,@1,@2,@3,@4,@5",); using (var db = new D ...

  10. 1 《JavaScript高级程序设计》学习笔记(1)

    欢迎关注本人的微信公众号"前端小填填",专注前端技术的基础和项目开发的学习. 首先,我将从<JavaScript高级程序设计>这本JavaScript学习者必看的经典教 ...