First quoted Ajaxfileupload.js did not go to csdn under their own
Next is the HTML
<input type= "file" id= "file1" name= "file" style= "Display:none" accept= "Image/x-png,image/gif,image/jpeg, Image/bmp "multiple=" multiple "/><button type= "button" class= "btn btn-info" id= "Btnfile" ><i class= "fa fa-cloud-upload" > upload </i></button>
which accept can specify the upload format multiple= "Multiple" This property allows for multiple file selection
JS section
$ ("#btnFile"). Click (function () {$ ("#file1"). Click (); }) $ ("#file1"). Change (function () {if ($ ("#file1"). Val (). length > 0) {ajaxfileupload (); } else {Swal ({title: ' Please choose to upload the file! ', Text: ', type: ' Info '}); } });
function ajaxfileupload () { $.ajaxfileupload ( &N Bsp { URL: '/financialreimbursement/financialreimb Ursement/upload ',//server-side request address for file upload type: ' Post ', &NBS P data: {Id: ' 123 ', Name: ' Add '},//This parameter is very rigorous, a wrong quote is not possible Secureuri:false,//Whether a security protocol is required, generally set to false Filee Lementid: ' file1 ',//File upload domain id DataType: ' json ',//return value type generally set to JSON&N Bsp success:function (data, status) //Server Success Response processing function { &N alert ("Upload success"); Bsp }, error:function (data , status, E)//server response failure handling function { &NBSP ; alert (e); } } )
Background section
Public ActionResult Upload () {NameValueCollection NVC = System.Web.HttpContext.Current.Request.Form;
String type = NVC. Get ("name");//Get Parameters
Httpfilecollection HFC = System.Web.HttpContext.Current.Request.Files;
if (HFC. Count > 0) { #region & nbsp; perform multiple file uploads for (int i = 0; i < HFC. Count; i++) { &NBSP ; var Filenamearr = Hfc[i]. Filename.split ('. '); &NBS P String FileName = DateTime.Now.ToString ("YYYYMMDDHHMMSS") + "_" + filenamearr[0] + "." + Filenamearr[1];&nbs P Imgpath + = "/allfileup/fortheattachment/" + FileName + ","; String IMGP = "/allfileup/fortheattachment/" + filen ame; string PhysicalpAth = Server.MapPath (IMGP); &NBSP;IF (! Directory.Exists (Server.MapPath ("/allfileup/fortheattachment"))///Storage path folder does not exist on auto new { &NB Sp;directory. CreateDirectory (Server.MapPath ("/allfileup/fortheattachment")); } Hfc[i]. SaveAs (PhysicalPath); }&NBS P #endregion }
Return Json (New {count = HFC. Count});//Returns the number of saved files
}
Write a very messy first write a little bit of format is not hahaha
Ajaxfileupload File Upload