开发者

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

开发者 https://www.devze.com 2023-01-26 06:42 出处:网络
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?
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

精彩评论

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