[HttpPost] [ValidateInput(false)] public ActionResult EditNews(NewsEntity news) { if (ModelState.IsValid) { news.Time = DateTime.Now; PE.Entry(news).State = EntityState.Modified;//修改 PE.SaveChanges(); return RedirectToAction("News"); } return View(news); }
删除Controller代码:
public ActionResult DeleteNews(int id) { var model = PE.NewsEntity.Find(id); PE.NewsEntity.Remove(model); PE.SaveChanges(); return RedirectToAction("News"); }