public ActionResult Contact(NoteBook model) { model.CreateDate = DateTime.Now; object imgCode = Session["ImgCode"]; if (imgCode.ToString() != model.ValCode.ToUpper()) { ModelState.AddModelError("ValCode", "验证码输入有误"); } if (!ModelState.IsValid) { return View(); } try { context.NoteBook.Add(model); context.SaveChanges(); TempData["SuccessMsg"] = "提交成功!我们将在第一时间和您联系!"; } catch (Exception ex) { ModelState.AddModelError("DbError", ex.Message); return View(); } return RedirectToAction("Contact"); }
public ActionResult EditNoteBook(NoteBook model) { if (!ModelState.IsValid) { return View(); } if (model.Id == 0) { try { context.NoteBook.Add(model); context.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError("DbError", ex.Message); } } else { var old = context.NoteBook.SingleOrDefault(t => t.Id == model.Id); old.Name = model.Name; old.Surname = model.Surname; old.Company = model.Company; old.Country = model.Country; old.Email = model.Email; old.Message = model.Message; old.Phone = model.Phone; context.SaveChanges(); } return View(); }
public ActionResult EditNoteBook(int? id) { var m = new NoteBook(); if (id.HasValue) { var old = context.NoteBook.SingleOrDefault(t => t.Id == id.Value); m = old ?? m; } return View(m); }
public ActionResult Contact() { var m = new NoteBook(); return View(m); }