public ActionResult Create() { var mediator = new Database.CategoryMediator(); var article = new Article(); var items = mediator.GetAllCategories().Select(category => new SelectListItem { Text = category.Name, Value = category.Id.ToString() }).ToList(); ViewBag.CategoryItems = items; return View(article); }
public ActionResult Create([Bind(Include = "Header, Body, CategoryId")] Article article) { // TODO : // Bruger skal ikke kunne trykke submit flere gange var categorymediator = new Database.CategoryMediator(); var articlemediator = new ArticleMediator(); #region itemsrep // skal finde en anden løsning, evt. et repository var items = categorymediator.GetAllCategories().Select(cat => new SelectListItem { Text = cat.Name, Value = cat.Id.ToString() }).ToList(); ViewBag.CategoryItems = items; #endregion var categoryid = article.CategoryId; var category = categorymediator.GetAllCategories().First(x => x.Id == categoryid); article.CategoryId = category.Id; if (ModelState.IsValid) { var service = new JsonService(); string path = service.CreateJson(article); article.Path = path; articlemediator.Save(article); return RedirectToAction("List", "Article"); } ViewBag.Error = "Kan ikke oprette"; return View(article); }