开发者

ASP.NET MVC2: How to return a file from a controller? [duplicate]

This question already has answers here: 开发者_运维问答 Closed 12 years ago.

Possible Duplicate:

How to create file and return it via FileResult in ASP.NET MVC?

ASP.NET MVC2: How to return a file from a controller?

I want to do this so the user can download the file from server.


        public 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" };
        }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜