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); }
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); } }