c# - Unable to upload multiple files -


i using asp.net mvc 5,jquery latest version. trying upload multiple files using jquery fileupload unable recieve multiple files.

view:

 <input id="fileupload" type="file" multiple="multiple" name="files[]"  >  <script type="text/javascript">     $(document).ready(function () {         $('#fileupload').fileupload({             datatype: 'json',             url: '/media/uploadfiles',             autoupload: true,             done: function (e, data) {              }         }).on('fileuploadprogressall', function (e, data) {             var progress = parseint(data.loaded / data.total * 100, 10);             $('.progress .progress-bar').css('width', progress + '%');         });     }); </script> 

controller:

 [httppost]         public contentresult uploadfiles()         {              foreach (string file in request.files)             { }         } 

here in request.files recieving 1 file.

your uploaded files sent 1 one.

you can change serve code

[httppost] public jsonresult uploadfiles() {     ilist<string> filessaved = new list<string>();      foreach (string file in request.files)     {     httppostedfilebase hpf = request.files[file];     if (hpf.contentlength > 0)     {         var filename = hpf.filename;         filessaved.add(filename);     }     }      return json(new {files = filessaved}, jsonrequestbehavior.denyget); } 

and insert breakpoint , see request goes through once each file you're sending.

the problem in client code. there's option in plugin singlefileuploads defaults true, can read here.

you can change client code setting singlefileuploads: false :

$(document).ready(function () {         $('#fileupload').fileupload({             datatype: 'json',             url: '/media/uploadfiles',             autoupload: true,             singlefileuploads: false,             done: function (e, data) {              }         }).on('fileuploadprogressall', function (e, data) {             var progress = parseint(data.loaded / data.total * 100, 10);             $('.progress .progress-bar').css('width', progress + '%');         }); }); 

and should work expected.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -