2010-11-23 12 views
1

可能性の重複:
How to create file and return it via FileResult in ASP.NET MVC?ASP.NET MVC2:コントローラからファイルを返す方法は?

ASP.NETのMVC2:コントローラからファイルを返すためにどのように?

ユーザーがサーバーからファイルをダウンロードできるようにしたいと思います。

+0

http://stackoverflow.com/questions/1375486/how-to-create-file-and-return-it-via-fileresult-in-asp-net-mvcの可能性のある重複*ヒント*: 'FileResult'はあなたが探しているものです。 –

答えて

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

関連する問題