1
Answer

how multiple file upload in jquery ajax submit?

Mani Kandan

Mani Kandan

7y
220
1
Hello all,
 
I am working on MVC 5, I want to save image on server from input type file uploader.
 
Form submit,
  1. secondForm: function (e) {  
  2. ar idfileTitle = document.getElementById("idfileTitle"); /*This fileuploader Id*/    
  3.   
  4. var idfileLogo = document.getElementById("idfileLogo"); /*This fileuploader Id*/    
  5.   
  6.  var json = {};  
  7.   
  8.            var hidvalue = $('#hdPrimUserFirstReg').val();  /*This is the hiddenfield Id*/
  9.            var hidJson = JSON.parse(hidvalue);  
  10.   
  11.            $.each($('#frmSubmitPremUserRegFirst').serializeArray(), function (i, field) {  
  12.                json[field.name] = field.value || '';  
  13.            });  
  14.   
  15.            hidJson.Form2 = json;  
  16.            $formData = new FormData();  
  17.            if (idfileTitle.files.length > 0) {  
  18.                for (var i = 0; i < idfileTitle.files.length; i++) {  
  19.                    $formData.append('file-' + i, idfileTitle.files[i]);  
  20.                }  
  21.            }  
  22.   
  23.            if (idfileLogo.files.length > 0) {  
  24.                for (var i = 0; i < idfileLogo.files.length; i++) {  
  25.                    $formData.append('file-' + i, idfileLogo.files[i]);  
  26.                }  
  27.            }  
  28.   
  29. /*Here 'hidJson' containing all form data*/      
  30.   
  31.            $.ajax({  
  32.                url: '../UserRegister/PremiumUserRegistration/' + hidJson,  
  33.                type: 'POST',  
  34.                data: $formData,  
  35.                dataType: 'json',  
  36.                contentType: false,  
  37.                processData: false,  
  38.                success: function ($data) {  
  39.                    $('#frmregitems').html($data);  
  40.                }  
  41.            }); 
 
Controller,
 
Here pageVM is null passing while assigning hidJson to PremiumUserRegistration action method as param.
  1. [HttpPost]  
  2.        public ActionResult PremiumUserRegistration(RegistrationModel pageVM)  
  3.        {  
  4. HttpFileCollectionBase files = Request.Files;  
  5.                foreach (string fil in files)  
  6.                {  
  7.   
  8.                 }  
  9.         } 
Here, Request.Files also containing only one image details, How can get multiple images from Request.Files ?
 
Please help me...
 
 
Answers (1)