

//獲取客戶端上傳的文件集合 HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; //相對路徑 string path = ""; //判斷文件是否存在 if (files.Count > 0) { //獲取擴展名 string extension = Path.GetExtension(files[0].FileName); if (!string.IsNullOrEmpty(extension)) { path = "/Content/images/" + Guid.NewGuid() + extension; //獲取文件集合中的第一個文件(每次只上傳一個文件) HttpPostedFile file = files[0]; string fullpath = System.Web.HttpContext.Current.Server.MapPath(path); file.SaveAs(fullpath); } }

$.ajaxFileUpload({ url: '/MarketingStrategyModule/MarketingStrategy/SaveMarketingBookForm?keyValue=' + keyValue, data: { name: entity.name, rule_rights: entity.rule_rights, state: entity.state, is_member: entity.is_member, start_date: entity.start_date, end_date: entity.end_date, dsc: entity.dsc, terminal: entity.terminal, members: entity.members, products: entity.products.replace(new RegExp('"', "gm"), "'") //entity.products是一個數組,需要先轉成JSON后,再進行正則替換,否則后台接受到的是“【{” }, type: "POST", fileElementId: 'uploadFile', dataType: 'json', success: function (data) { bpm.loading(false); if (data.code == 200) { //保存成功后才回調 if (!!callBack) { callBack(); } bpm.alert.success('保存成功'); bpm.layerClose(window.name); } else { bpm.alert.warning(data.info); } } });