上传使用Jquery上传文件插件,IEnumerable<不包含文件

本文关键字:文件 包含 IEnumerable 插件 Jquery | 更新日期: 2023-09-27 18:02:28

我使用jquery上传文件插件来上传多个文件。我已经添加了css和javascript文件上传参考。在填写客户端名称并添加一些文件附件后,我提交了表单,但由于IEnumerable为空,我无法保存该文件。我做错了什么?

视图

@using (Html.BeginForm()) {
    @Html.LabelFor(model => model.Client)
    @Html.DisplayFor(model => model.Client.Name)
    <div id="fileuploader">Upload</div>
    <input type="submit" value="Save" class="btn btn-default" />
}
@section Styles {
    <link href="~/Content/uploadfile.css" rel="stylesheet">
}
@section Scripts {
    <script src="~/Scripts/jquery.uploadfile.js"></script>
    <script>
        $(document).ready(function () {
            $("#fileuploader").uploadFile({
                url: "/Attachment/Upload/",
                dragDrop: true,
                multiple: true,
                autoSubmit: false,
                fileName: "myFile",
                returnType: "json",
                showDone: false,
                showDelete: true,
                deleteCallback: function (data, pd) {
                    for (var i = 0; i < data.length; i++) {
                        $.post("/Attachment/Delete/", { op: "delete", name: data[i] },
                            function (resp, textStatus, jqXHR) {
                                //Show Message  
                                alert("File Deleted");
                            });
                    }
                    pd.statusbar.hide(); //You choice.
                }
            });
        });
    </script>
}
控制器

public ActionResult Edit(Client client, IEnumerable<HttpPostedFileBase> myFile) {
    ...
}

上传使用Jquery上传文件插件,IEnumerable<不包含文件

enctype = "multipart/form-data"放到你的表单上

剃刀例子

@using (Html.BeginForm("Upload", "Upload", FormMethod.Post, 
                                  new { enctype = "multipart/form-data" }))
{
....
}