【问题标题】:ASP.NET MVC2: How to return a file from a controller? [duplicate]ASP.NET MVC2:如何从控制器返回文件? [复制]
【发布时间】:2010-11-23 21:33:06
【问题描述】:

可能重复:
How to create file and return it via FileResult in ASP.NET MVC?

ASP.NET MVC2:如何从控制器返回文件?

我想这样做,以便用户可以从服务器下载文件。

【问题讨论】:

标签: asp.net asp.net-mvc-2


【解决方案1】:
公共 ActionResult Csv(int pid) { var csv = this.Repo.GetCsv(pid); var fileContents = Encoding.GetEncoding(1251).GetBytes(csv); return new FileContentResult(fileContents, "application/vnd.ms-excel") { FileDownloadName = "Report-" + pid + ".csv" }; }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-29
    • 1970-01-01
    • 2012-07-18
    • 2012-03-21
    • 2023-04-08
    相关资源
    最近更新 更多