public ActionResult SingleUpload() { Picture model = new Picture(); try { string uploadPath = Server.MapPath("~/UploadFiles"); if (!Directory.Exists(uploadPath)) { Directory.CreateDirectory(uploadPath); } HttpPostedFileBase f = Request.Files[0]; String Ids = Request.Form["id"].ToString(); string ext = Path.GetExtension(f.FileName); Guid g = Guid.NewGuid(); string filename = Path.Combine(uploadPath, g + ext); f.SaveAs(filename); int id = 0; model.Src = string.Format("UploadFiles/{0}{1}", g, ext); model.NewName = g + ext; model.FullName = filename; model.Name = f.FileName; id = pictureService.CreateModel(model); DeletePictures(Ids); return(Json(new { status = true, name = model.Name, id, url = model.Src })); } catch (Exception e) { if (System.IO.File.Exists(model.FullName)) { System.IO.File.Delete(model.FullName); } return(Json(new { status = false, msg = "上传失败!", errmsg = e.Message })); } }