public ActionResult Edit(ManageAlbumViewModel model, System.Web.HttpPostedFileBase file) { if (!ModelState.IsValid) { return(View(model)); } if (file != null && file.ContentLength > 0) { var fileName = System.IO.Path.Combine(Request.MapPath("~/Content/Album/"), System.IO.Path.GetFileName(file.FileName)); file.SaveAs(fileName); model.Cover = System.IO.Path.GetFileName(file.FileName); string oldCover = _db.tbl_Album.SingleOrDefault(a => a.album_Id == model.Id).album_Cover; if (model.Cover != oldCover && oldCover != "Album_1.jpg") { ImageManager.Delete(Server.MapPath("~/Content/Album/" + oldCover)); } } AlbumManager.Edit(model); ModelState.AddModelError("", "修改成功"); return(RedirectToAction("Edit", new { id = model.Id })); }