public virtual ActionResult Create(DepartView depart) { try { if (ModelState.IsValid) { var newDepart = new Depart(); if (TryUpdateModel(newDepart)) { Repository.Add(newDepart); Repository.Save(); return null; } return Content("不能保存此部门"); } return Content("部门输入信息不符合规定"); } catch { return Content("出错了"); } }
public virtual ActionResult Edit(int id, DepartView departview) { if (ModelState.IsValid) { try { var depart = Repository.All<Depart>().SingleOrDefault(x => x.DepartId.Equals(id)); UpdateModel(depart); Repository.Save(); return Content(""); } catch { return Content(""); } } ModelState.AddModelError("","输入的内容符合要求"); return View(departview); }