C# 文件(图片)下载
视图:
@model List<string>
<table>
<tr>
<th>文件</th>
<th>操作</th>
</tr>
@for (int i = 0; i < Model.Count; i++)
{
<tr>
<td>@Model[i].ToString()</td>
<td>@Html.ActionLink("下载", "XZ", new { fileName = Model[i].ToString() })</td>
</tr>
}
</table>
控制器:
public ActionResult UpFile1()
{
var a = new List<string> { "38.jpg", "下载文件1.png", "报错信息.docx" };
return View(a);
}
public FileResult XZ(string fileName)
{
string fileDz = "~/App_Data/File/" + fileName;
return File(fileDz, "application/force-download", Path.GetFileName(fileDz));
}