public ActionResult Edit(int id, EF.Attachment model, FormCollection collection) { string virtualPath = ""; string bmxyPath = ""; //客户端已处理ajax重复提交问题(ajax提交一次,表单再提交一次) string msg = "保存失败"; try { // TODO: Add update logic here //var statistical = bllStatistical.GetModel(id); if (id > 0 && model != null) { if (Request.Files.Count > 0) { HttpPostedFileBase filec = Request.Files[0]; // HttpPostedFileBase files = Request.Files[1]; //// 如果没有上传文件 //if (file == null || string.IsNullOrWhiteSpace(filec.FileName) || file.ContentLength == 0) //{ // msg = "未检测到上传的文件,请重新上传"; // return Content(msg); //} //允许的文件类型 string[] extension = { ".jpg", ".docx", "doc", ".pdf" }; if (!extension.Contains(System.IO.Path.GetExtension(filec.FileName))) { msg = "导入的文件必须是excel格式"; return(Content(msg)); } //Console.WriteLine(extension.Contains(System.IO.Path.GetExtension(file.FileName))); // 保存到 {~/UploadFile/OA/AttendanceMonthStatistical/日期/文件名} 文件夹中,名称不变 string filename = System.IO.Path.GetFileName(filec.FileName); //string filen = System.IO.Path.GetFileName(files.FileName); virtualPath = string.Format("/UploadFile/Areas/Attachment/ContactFile/{0}/{1}", DateTime.Now.ToString("yyyy-MM-dd"), filename); //bmxyPath = string.Format("/UploadFile/Areas/Attachment/SecrecyAgreement/{0}/{1}", DateTime.Now.ToString("yyyy-MM-dd"), filen); //文件系统不能使用虚拟路径 string path = this.Server.MapPath(virtualPath); // string path1 = this.Server.MapPath(bmxyPath); DirectoryInfo dirInfo = Directory.GetParent(path); //DirectoryInfo dirInfo1 = Directory.GetParent(path1); if (!dirInfo.Exists) { dirInfo.Create(); } //if (!dirInfo1.Exists) //{ // dirInfo1.Create(); //} filec.SaveAs(path); // files.SaveAs(path1); model.DocPath = virtualPath; //return RedirectToAction("Index"); model.CreateUser = "******"; model.UpdateUser = "******"; model.UpdateTime = DateTime.Now; model.CreateTime = DateTime.Now; model.AttachmentId = id; int result = attachmentDAL.Update(model); if (result > 0) { msg = "保存成功"; } //return RedirectToAction("Index"); } } return(Content(msg)); } catch { //return View(); return(Content(msg)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Attachment model) { return(dal.Update(model)); }