1

I am using html5 FormData to send files to the server. However, the incoming photos object is always null. I can see the files being send in the network monitor. I think the type that i expect is wrong. Currently i have:

[HttpPost]
public JsonResult AssignImages(IEnumerable<HttpPostedFileBase> photos)
{
    return new JsonResult();
}

I also tried:

[HttpPost]
public JsonResult AssignImages(IEnumerable<HttpPostedFile> photos)
{
    return new JsonResult();
}

My JS:

function sendFileToServer(formData, status) {
    var uploadURL = "/Inventory/AssignImages"; //Upload URL
    $.ajax({
        url: uploadURL,
        type: "POST",
        contentType: false,
        processData: false,
        cache: false,
        data: formData,
        success: function (data) {
        }
    });

function handleFileUpload(files){
     var fd = new FormData();
     for (var i = 0; i < files.length; i++) {
                fd.append('File', files[i]);
                sendFileToServer(fd, status);
    }
}
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
setlio
  • 726
  • 2
  • 13
  • 32

1 Answers1

1

You have to get the files from the Request.Files collection.

See https://stackoverflow.com/a/14674531/120955

Community
  • 1
  • 1
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315