例如:
public ActionResult Image(string id) [HttpPost] [ValidateInput(false)] //避免Controller檢查Script攻擊 public ActionResult EditBoardHonor([Bind(Exclude = "ValidDate,CreateDate")]Models.BoardHonor postback) { postback.CreateDate = DateTime.Now; postback.ValidDate = DateTime.Now; using (MvcBodyApp.Models.BodyDBEntities db = new BodyDBEntities()) { var result = (from s in db.BoardHonor where s.BoardHonorId == postback.BoardHonorId select s).FirstOrDefault(); if (TryUpdateModel(result)) //檢查資料繫結是否正常 { db.SaveChanges(); ViewData["resultMsg"] = String.Format("【{0}】編輯成功", postback.Title); return View(postback); } } ViewData["resultMsg"] = "編輯失敗"; return View(postback); }
沒有留言:
張貼留言