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
In Action Sie passieren "id" Parameter, während Sie sollten "file" wie in Download Aktion – Azargoth
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
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 " –