// GET: Comment/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } CommentModel comment = db.Comments.Find(id); if (comment == null) { return HttpNotFound(); } EditCommentVievModel viewModel = new EditCommentVievModel() { CommentText = comment.CommentText, Id = comment.CommentID }; //ViewBag.Article_ArticleID = new SelectList(db.Articles, "ArticleID", "ArticleTitle", commentModel.Article_ArticleID); //ViewBag.User_Id = new SelectList(db.Users, "Id", "Email", commentModel.User_Id); return View(viewModel); }
public ActionResult Edit(EditCommentVievModel viewModel) { if (ModelState.IsValid) { CommentModel comment = db.Comments.Find(viewModel.Id); comment.CommentText = viewModel.CommentText; db.Entry(comment).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } //ViewBag.Article_ArticleID = new SelectList(db.Articles, "ArticleID", "ArticleTitle", commentModel.Article_ArticleID); //ViewBag.User_Id = new SelectList(db.Users, "Id", "Email", commentModel.User_Id); return View(viewModel); }