我需要创建上传多个文件的方法。
这是我的后端模型,它以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,看起来像这样
但是我得到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();
}
});