我正在研究MVC 5,我想从输入类型文件上传器中保存服务器上的图像。
表单提交,
secondForm: function (e) {
ar idfileTitle = document.getElementById("idfileTitle"); /*This fileuploader Id*/
var idfileLogo = document.getElementById("idfileLogo"); /*This fileuploader Id*/
var json = {};
var hidvalue = $('#hdPrimUserFirstReg').val(); /*This is the hiddenfield Id*/
var hidJson = JSON.parse(hidvalue);
$.each($('#frmSubmitPremUserRegFirst').serializeArray(), function (i, field) {
json[field.name] = field.value || '';
});
hidJson.Form2 = json;
$formData = new FormData();
if (idfileTitle.files.length > 0) {
for (var i = 0; i < idfileTitle.files.length; i++) {
$formData.append('file-' + i, idfileTitle.files[i]);
}
}
if (idfileLogo.files.length > 0) {
for (var i = 0; i < idfileLogo.files.length; i++) {
$formData.append('file-' + i, idfileLogo.files[i]);
}
}
/*Here 'hidJson' containing all form data*/
$.ajax({
url: '../UserRegister/PremiumUserRegistration/' + hidJson,
type: 'POST',
data: $formData,
dataType: 'json',
contentType: false,
processData: false,
success: function ($data) {
$('#frmregitems').html($data);
}
});
控制器,
此处pageVM
在将hidJson
转换为PremiumUserRegistration
操作方法作为参数时为空传递。
[HttpPost]
public ActionResult PremiumUserRegistration(RegistrationModel pageVM)
{
HttpFileCollectionBase files = Request.Files;
foreach (string fil in files)
{
}
}
此处,Request.Files
也只包含一个图片详情,如何从Request.Files
获取多张图片?
请帮帮我......