WebMethod文件上传

时间:2018-12-07 08:59:41

标签: c# asmx webmethod

我需要创建上传多个文件的方法。
这是我的后端模型,它以public void ImageUpload(IEnumerable<ImageModel> images)

的形式传递
public class ImageModel
{
    public int EntityId { get; set; }
    public string FileName { get; set; }
    public string AltText { get; set; }
    public byte[] Content { get; set; }
    public int ImageRoomId { get; set; }
}

从js我发送formdata,看起来像这样

enter image description here

但是我得到System.IndexOutOfRangeException: Index was outside the bounds of the array.

我不知道哪里出了错。我需要使用其他任何内容类型吗?

更新

[WebMethod]
public string developmentimageupload(ImageModel[] file)
{
    return "Ok";
}

JS:

var formData = new FormData();
var formFields = container.querySelectorAll('input[type=text], select');

for(i = 0; i < fileList.length; i++){
    formData.set('File[' + i + '].Content', fileList[i]);
    formData.set('File[' + i + '].FileName', fileList[i].name);
}

for(var i = 0; i < formFields.length; i++){
    formData.set(formFields[i].name, formFields[i].value);
}

$.ajax({
    url: window.siteAdminProperties.Feeds.DevelopmentBulkImagesUploadUrl,
    type: 'POST',
    data: formData,
    processData: false,
    contentType: false,
    success: function (data) {
        $('.js-images-uploader').hide();
        $('.js-images-uploaded').show();
    }
});

0 个答案:

没有答案