Пример #1
0
        //
        // GET: /Blog/Create
        public ActionResult Create()
        {
            //Get All Blogs and populate the dropDown using select List
            IEnumerable<Blog> selectList = myDBContext.Blogs.ToList<Blog>();
            //SelectList blogsList = new SelectList(blogs,"Id","blogName");
               // ViewData["selectList"] = blogsList;

            BlogCreateViewModel blogsList = new BlogCreateViewModel { blogs = selectList };

            return View(blogsList);
        }
Пример #2
0
        public ActionResult Create(Blog blog)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    myDBContext.Blogs.Add(blog);
                    myDBContext.SaveChanges();
                }
            }
            catch
            {
            }

              IEnumerable<Blog> selectList = myDBContext.Blogs.ToList<Blog>();
              BlogCreateViewModel blogsList = new BlogCreateViewModel { blogs = selectList, blog = blog };

              return View(blogsList);
        }