我正在使用jquery upload file plugin上传多个文件。我添加了css和javascript fileupload引用。填写客户端名称并添加一些文件附件后,我提交表单,但由于IEnumerable为null,我无法保存该文件。我做错了什么?
查看
@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) {
...
}
答案 0 :(得分:2)
将enctype = "multipart/form-data"
放在表单上。
Razor示例
@using (Html.BeginForm("Upload", "Upload", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
....
}