コード例 #1
0
 public ActionResult Index()
 {
     var vm = new CommentsVM();
     vm.Comments = _db.GetComments();
     vm.Comment = new Comment();
     return View(vm);
 }
コード例 #2
0
        public ActionResult Index(Comment comment)
        {
            if (ModelState.IsValid)
            {
                comment.CreatedOn = DateTime.Now;
                _db.AddComment(comment);
                _db.Save();
                return RedirectToAction("Index");
            }

            // error return view
            var vm = new CommentsVM();
            vm.Comment = comment;
            vm.Comments = _db.GetComments();
            return View("Index", vm);
        }