Question

I'm using jquery upload file plugin to upload multiple file. I have added css and javascript fileupload reference. After fill client name and add some file attachment, I submit the form, but I cannot save the file because IEnumerable is null. What I'm doing wrong?

View

@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>
}

Controller

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

Solution

Put enctype = "multipart/form-data" on your form.

Razor example

@using (Html.BeginForm("Upload", "Upload", FormMethod.Post, 
                                  new { enctype = "multipart/form-data" }))
{
....
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top