2016-04-08 9 views
1

Hallo Ich versuche, Datei vom Server herunterzuladen.Datei herunterladen von Details anzeigen MVC 5

Hier ist mein Controller

public ActionResult Downloads() 
    { 
     var dir = new System.IO.DirectoryInfo(Server.MapPath("~/Content/AnnFiles/")); 
     System.IO.FileInfo[] fileNames = dir.GetFiles("*.*"); List<string> items = new List<string>(); 
     foreach (var file in fileNames) 
     { 
      items.Add(file.Name); 
     } 
     return View(items); 
    } 

    public FileResult Download(string file) 
    { 

     var FileVirtualPath = "~/Content/AnnFiles/" + file; 
     return File(FileVirtualPath, "application/force-download", Path.GetFileName(FileVirtualPath)); 
    } 

und meiner Ansicht nach

@Html.ActionLink("Download", "Download", "announcement", new { id = Model.file}) 

Es funktioniert nicht. Es gibt den Fehler

Could not find a part of the path 'C:\Myprojects\MyprojectName\MyprojectName\Content\AnnFiles\' 

Jede Idee? danke

+2

In Action Sie passieren "id" Parameter, während Sie sollten "file" wie in Download Aktion – Azargoth

+0

Dankeschön erklärt, ich ändert es in @ Html.ActionLink ("Download", "Download", "Ankündigung", Modell.datei). Aber es gibt denselben Fehler zurück. Beim Debuggen mit Firebug wird der Link als – touinta

+1

gerendert. Ich denke, der Ancor-Helfer muss wie "@ Html.ActionLink (" Download "," Download "," Ankündigung ", neu {file = Model.file})" sein sollte als "/announcement/Download?file=[yourModel.File" gerendert werden " –

Antwort