1 function fileUpload() { 2 var formData = new FormData(); 3 formData.append("param1", "参数1"); 4 formData.append("param2", "参数2"); 5 formData.append("file", $('#uploadfile')[0].files[0]); 6 $.ajax({ 7 url: 'Dosomething/Doit', 8 //url 9 type: 'post', 10 data: formData, 11 processData: false, //必须false才会避开jQuery对 formdata 的默认处理 12 contentType: false, //必须false才会自动加上正确的Content-Type 13 async: false 14 }).done(function(res) {; 15 }).fail(function(res)) {; 16 }); 17 }
以上是前端js
1 [HttpPost] 2 public bool Doit() 3 { 4 string p1=Request.Form["param1"]; //普通参数获取 5 string p2=Request.Form["param2"]; 6 var file = Request.Files["file"]; 7 foreach(string upload in Request.Files.AllKeys) 8 { 9 HttpPostedFileBase file=Request.Files[uplooad]; //file可能为null 10 } 11 12 return true; 13 }
以上是后端接收.