文章出處
View Code
View Code
文章列表
JS代碼:

//保存 function btnAdd() { var formData = new FormData($("#frm")[0]); $.ajax({ url: "/Admin/ContentManage/SaveEdit", type: "POST", data: formData, contentType: false, //必須false才會避開jQuery對 formdata 的默認處理 XMLHttpRequest會對 formdata 進行正確的處理 processData: false, //必須false才會自動加上正確的Content-Type success: function (data) { if (data == "OK") { alert("保存成功"); $.iDialog("close"); //刷新父頁面 } else { alert("保存失敗:" + data); } } }); }
ASP.NET MVC后臺代碼:

//首先判斷路徑是否存在,不存在則創建路徑 string path = Path.Combine(System.Configuration.ConfigurationManager.AppSettings["UploadsFiles"], folder + "/" + DateTime.Now.ToString("yyyyMMdd") + "/"); string physicalPath = server.MapPath(path); if (!Directory.Exists(physicalPath)) { Directory.CreateDirectory(physicalPath); } HttpPostedFileBase file = request.Files[0]; string newFileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName); string savePath = Path.Combine(physicalPath, newFileName); file.SaveAs(savePath); fileName = file.FileName; string url = Path.Combine(path, newFileName); return url;
文章列表
全站熱搜