//组装上传文件数据 var paramer = new FormData(); paramer.append("FILE1",$("input[name=FILE1]").get(0).files[0]); $.ajax({ url: "/Platform/VCard/UpLoadFile",contentType: false,//必须false才会自动加上正确的Content-Type processData: false,//必须false才会避开jQuery对 formdata 的默认处理.XMLHttpRequest会对 formdata 进行正确的处理. type: 'POST',data: paramer,success: function (data) { //拿到上传完文件返回的服务器路径 var FILE1 = data.FILE1; //已List<model> ListModel 的方式提交至controller var ListModel = []; $('.div-EdBackground').each(function () { var thisItem = $(this); ListModel.push({ EdStartTime: thisItem.find("input[name=EdStartTime]").val(),EdEndTime: thisItem.find('input[name=EdEndTime]').val(),SchoolName: thisItem.find('input[name=SchoolName]').val(),NUEE: thisItem.find('input[name=NUEE]').val(),MajorName: thisItem.find('input[name=MajorName]').val(),Degree: thisItem.find('select[name=Degree]').val() }) }); $.ajax({ url: "/Platform/VCard/Add",data: { FILEURL:FILE1,ListModel: ListModel },contentType: "json",success: function (res) { if (res) { parent.layer.close(index); MessageBox("发布成功"); } else { parent.layer.close(index); MessageBox("发布失败"); } } }); } });
后台 接收文件的方法
public JsonResult UpLoadFile() { try { //上传公众号二维码 string FileUrl = UploadFile(Request.Files["FILE1"],EmployeeID,EmployeeEpID); return Json(new { FILE1 = FileUrl }); } catch (Exception ex) { throw ex; } }
接收List
public JsonResult Add(List<model> list) { try { return Json(“”); } catch (Exception ex) { throw ex; } }原文链接:https://www.f2er.com/ajax/160663.html