public ActionResult Create_Post()
        {
            var blogPost = new BlogPost();
            // analogous to receiving the blogPost as a paramater
            if (!TryUpdateModel(blogPost))
            {
                //...
            }

            if (ModelState.IsValid)
            {
                BlogPostService.Add(blogPost);
                return RedirectToAction("Index");
            }
            else // data is invalid
            {
                return View(blogPost);
            }
        }
Esempio n. 2
0
 public void Add(BlogPost blogPost)
 {
     blogPost.Id = _blogPosts.Last().Id + 1;
     _blogPosts.Add(blogPost);
 }
 public ActionResult Create()
 {
     var initialBlogPost = new BlogPost {PublishedOnDate = DateTime.Now.Date};
     return View(initialBlogPost);
 }