public ActionResult MaintainPlan(int id, int? AssetId, FormCollection collection) { AssetMaintain a = db.AssetMaintains.Find(id);; if(a==null) { a = new AssetMaintain(); } TryUpdateModel(a, "", new string[] { }, new string[] { "DoneDate", "DoneDetail" }, collection); if(ModelState.IsValid) { if(id==0) { a.AssetId = (int) AssetId; db.AssetMaintains.Add(a); } db.SaveChanges(); return Redirect("~/content/close.htm"); } return View(a); }
public ActionResult MaintainPlan(int id, int? assetid) { AssetMaintain au; Asset asset; if (id == 0) { asset = db.Assets.Find(assetid); if (asset == null) {//ToDo:异常处理 } au = new AssetMaintain(); } else { au = db.AssetMaintains.Find(id); if (au == null) { //ToDo:异常处理 } asset = db.Assets.Find(au.AssetId); } ViewBag.asset = asset; return View(au); }