ASP.NET MVC3手把手教你构建Web(2)

[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"); }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjwxsg.html