我正在使用MVC4,我的一个视图包含超链接,允许从视图下载文档。实际上,我还想显示一个链接,允许下载压缩在.zip存档中的所有文件。我的文件以varbinary格式存储在我的数据库中。
我的下载动作:
public ActionResult DownloadDocument(long id)
{
Document element = db.Documents.Single(obj => obj.Id_Document == id);
try
{
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment; Filename=\"" + element.Name + "\"");
Response.AddHeader("Content-Transfer-Encoding", "Binary");
Response.BinaryWrite(element.Buffer);
Response.Flush();
Response.End();
}
catch(Exception ex)
{
}
return View("Details", element.ProductAllocationLog);
}
我的观点:
@model BuSIMaterial.Models.ProductAllocationLog
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm("Create", "ProductAllocationLog", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>ProductAllocationLog</legend>
<div class="editor-label">
Date :
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Date, new { @class = "datepicker"})
@Html.ValidationMessageFor(model => model.Date)
</div>
<div class="editor-label">
Message :
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.Message)
@Html.ValidationMessageFor(model => model.Message)
</div>
<div class="editor-label">
Allocation :
</div>
<div class="editor-field">
@Html.DropDownList("Id_ProductAllocation", String.Empty)
@Html.ValidationMessageFor(model => model.Id_ProductAllocation)
</div>
<p>
<input type="file" name="files" multiple="multiple"/>
</p>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
关于我可以用来做这件事的方法吗?感谢。