public void EditComment(EditCommentBm bind) { Comment model = this.Context.Comments.Find(bind.Id); model.CommentDescription = bind.CommentDescription; model.CommentType = bind.CommentType; model.ReminderDate = bind.ReminderDate; try { // Your code... // Could also be before try if you know the exception occurs in SaveChanges this.Context.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }
public ActionResult Edit([Bind(Include = "Id, CommentDescription,CommentType,ReminderDate")] EditCommentBm bind) { if (this.ModelState.IsValid) { this.service.EditComment(bind); return(this.RedirectToAction("All")); } EditCommentVm vm = this.service.GetEditVm(bind.Id); return(this.View(vm)); }