您好我尝试从服务器下载文件。
这是我的控制器
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\'
有什么想法吗? 谢谢
答案 0 :(得分:2)
您需要使用以下重载;
@Html.ActionLink("Download", "Download", "announcement", new { file = Model.file}, null);
在末尾添加null参数使用以下内容:
<强> Fiddle 强>