I am using jQuery Multiple File Upload Plugin to upload multiple images. But it forms messages only 1, top, element. Violinist (POST):
POST /Images/UploadImages HTTP/1.1 Host: localhost:4793 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:4793/images Cookie: .ASPXAUTH=EFAC4E03FA49056788028048AE1B099D3EB6D1D61AFB8E830C117297471D5689EC52EF40C7FE2CEF98FF6B7C8CAD3AB741A5E78F447AB361A2BDD501331A88C7B75120611CEA4FECA40D972BB9401472 Content-Type: multipart/form-data; boundary=---------------------------1509898581730 Content-Length: 290022 -----------------------------1509898581730 Content-Disposition: form-data; name="album" 1 -----------------------------1509898581730 Content-Disposition: form-data; name="file[]"; filename="Blue hills.jpg" Content-Type: image/jpeg ...
Here is my code:
<% using (Html.BeginForm("UploadImages", "Images", FormMethod.Post, new { enctype = "multipart/form-data"})) {%> <%= Html.DropDownList("album", (IEnumerable<SelectListItem>)ViewData["Albums"])%> <br /> <input type="file" name="file[]" id="file" class="multi" accept="jpg|png" /> <br /> <input type="submit" name="submit" value="Submit" /> <% } %>
And the controller code:
public ActionResult UploadImages(FormCollection formValue) { foreach (string file in Request.Files) { HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase; if (hpf.ContentLength == 0) continue;
Please tell me how to solve the problem. Perhaps you can advise in another way to allow the user to upload multiple images. TIA
PS. In addition to the html code generated by the sript controls:
<input id="file" class="multi" type="file" accept="jpg|png" name="file[]" style="position: absolute; top: -3000px;"/> <input id="file_F1" class="multi MultiFile" type="file" accept="jpg|png" name="file[]" style="position: absolute; top: -3000px;"/> <input id="file_F2" class="multi MultiFile" type="file" accept="jpg|png" name="file[]" style="position: absolute; top: -3000px;"/> <input id="file_F3" class="multi MultiFile" type="file" accept="jpg|png" name="file[]" style="position: absolute; top: -3000px;"/> <input id="file_F4" class="multi MultiFile" type="file" accept="jpg|png" name="file[]"/>
1gn1ter
source share