0

我正在使用 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>

关于我可以用来做到这一点的方式的任何想法?谢谢。

4

0 回答 0