ASP.NET - How to send multiple files to the controler using AJAX and Formdata?

0

I have the following code:

JAVASCRIPT:

$(function () {

$('form[enctype="multipart/form-data"]').submit(function (event) {

    event.preventDefault();
    event.stopPropagation();

    var formData = new FormData();
    formData.append('ObjectId', '1');
    formData.append('File', $(this).find('[name="File"]').prop('files'));

    $.ajax({
        type: "POST",
        url: '/Employee/FileUpload',
        data: formData,
        dataType: "json",
        contentType: false,
        processData: false,
        success: function (data) {

        },
    });
});

});

CONTREOLLER:

[HttpPost]
public ActionResult FileUpload(string ObjectId, string UnityId, IEnumerable<HttpPostedFileBase> File)
{
    .. Meu código
}

The case is that I need the 'File' parameter declared in the FileUpload method to receive two files that have been selected in the input [name="File"] simultaneously.

Using Ienumerable did not work.

What would be the correct way to do this?

    
asked by anonymous 27.10.2018 / 20:47

0 answers