public ActionResult Create([Bind(Include = "Id,Title,Description")] Board board) { board.User = GetUser(); if (ModelState.IsValid) { db.Board.Add(board); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(board)); }
public JsonResult DeleteFile(int id) { var entity = _context.FileMgmt.FirstOrDefault(x => x.Id == id); if (entity == null) { return(Json(new { code = 1, msg = "数据不存在" })); } string webRootPath = _hostingEnvironment.WebRootPath; string filePath = webRootPath + entity.Url; if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } _context.FileMgmt.Remove(entity); _context.SaveChanges(); return(Json(new { code = 0 })); }