asp.net mvc return file result

  asp.net mvc返回文件:

asp.net mvc return file result
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 == 0?"学员":"教练";
                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(936).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

 

asp.net mvc return file result,布布扣,bubuko.com

asp.net mvc return file result

上一篇:《大型网站技术架构》读书笔记[3] - 架构核心五要素


下一篇:MVVM架构~knockoutjs系列之验证信息自定义输出~续