2010-11-23 5 views
1

Mögliche Duplizieren:
How to create file and return it via FileResult in ASP.NET MVC?ASP.NET MVC2: Wie man eine Datei von einem Controller zurückgibt?

ASP.NET MVC2: Wie eine Datei von einem Controller zurück?

Ich möchte dies tun, damit der Benutzer die Datei vom Server herunterladen kann.

+0

Mögliche Duplikat http://stackoverflow.com/questions/1375486/how-to-create-file-and-return-it-via-fileresult-in-asp-net-mvc * Hinweis *: 'FileResult' ist was du suchst. –

Antwort

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

Verwandte Themen