// GET: Articles/Create public ActionResult Create() { db = new IdentityDBEntities(); ViewBag.Idc = new SelectList(db.Categories, "Id", "libelle"); //ViewBag.Idc = new SelectList(db.Categories, "Id", "libelle"); return(View()); }
// Create new article using HttpPost (Bind => Binding field on view) public ActionResult Create([Bind(Include = "Ida,description,image,Userid,Idc,titre")] Article article, HttpPostedFileBase image) { if (ModelState.IsValid) { if (image != null) { article.image = image.FileName; } db = new IdentityDBEntities(); // Add article to database article.UserId = System.Web.HttpContext.Current.User.Identity.GetUserId(); article.Idc = Convert.ToInt32(Request["Idc"]); db.Articles.Add(article); ViewBag.Idcc = new SelectList(db.Categories, "Id", "libelle"); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(article)); }