こんにちは私はサーバーからファイルをダウンロードしようとしています。ファイルをダウンロード詳細ビューからMVC 5
は、ここに私のコントローラ
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));
}
で、私の見解
@Html.ActionLink("Download", "Download", "announcement", new { id = Model.file})
にそれは動作しません。エラーを返します
Could not find a part of the path 'C:\Myprojects\MyprojectName\MyprojectName\Content\AnnFiles\'
ご存知ですか? ありがとう
あなたは "ファイル" を使用する必要がありながら、あなたは、 "ID" パラメータを渡しますダウンロードアクション – Azargoth
にありがとう、私はそれを@ Html.ActionLink( "ダウンロード"、 "ダウンロード"、 "アナウンス" Model.file)。しかし、それは同じエラーを返します。 Firebugでデバッグすると、リンクがDownload – touinta
と表示されます。ancorヘルパーは、 "@ Html.ActionLink(" Download "、" Download "、" announcement "、new {file = Model.file})のようにする必要があります。 "/announcement/Download?file=[yourModel.File"としてレンダリングする必要があります。 –