私は MVC4 を使用しており、ビューの 1 つに、ビューからドキュメントをダウンロードできるハイパー リンクが含まれています。実際、.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>
それを行うために使用できる方法について何か考えはありますか? ありがとう。