日期:2014-05-18 浏览次数:20428 次
public ActionResult Create() { var db = new dbContent(); var list = from p in db.NewsType orderby p.SortId descending select p; ViewBag.TypeId = new SelectList(list, "TypeId", "TypeName"); return View(); } [HttpPost] [ValidateInput(false)] public ActionResult Create(News model) { try { using (var db = new dbContent()) { db.News.AddObject(model); db.SaveChanges(); return RedirectToAction("Index"); } } catch { var db = new dbContent(); var list = from p in db.NewsType orderby p.SortId descending select p; ViewBag.TypeId = new SelectList(list, "TypeId", "TypeName", model.NewsType.TypeId); return View(model); } }