Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
how multiple file upload in jquery ajax submit?
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Mani Kandan
7y
218
1
Reply
Hello all,
I am working on MVC 5, I want to save image on server from input type file uploader.
Form submit,
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);
}
});
Controller,
Here
pageVM
is null passing while assigning
hidJson
to
PremiumUserRegistration
action method as param.
[HttpPost]
public
ActionResult PremiumUserRegistration(RegistrationModel pageVM)
{
HttpFileCollectionBase files = Request.Files;
foreach
(
string
fil
in
files)
{
}
}
Here,
Request.Files
also containing only one image details, How can get multiple images from
Request.Files
?
Please help me...
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Queried data from Controller to Partial View
How to make a grdview field value a link -Anchor link