예제 #1
0
        public ActionResult Create()
        {
            var categories = mongo.GetDatabase("ddd").GetCollection<NewsCategoryModel>("newscategories").FindAll();

            ViewBag.categories = new SelectList(categories, "Id", "CategoryName");

            var news = new NewsModel()
            {
                PubDate = DateTime.Now
            };
            return View(news);
        }
예제 #2
0
        public ActionResult Create(NewsModel model, string categoryId)
        {
            var news = mongo.GetDatabase("ddd").GetCollection<NewsModel>("news");
            
            try
            {
                
                model.Category = new MongoDBRef("newscategories", BsonValue.Create(categoryId));

                news.Insert(model);
                return RedirectToAction("Index");
            }
            catch
            {
                throw;
                //return View(model);
            }
        }