public ActionResult Create([Bind(Include = "OpdrachtNummer,WerkInstructie,DatumUitvoering,KabelLeverancier,Waarnemingen,Image,Bedrijfsuren,AflegRedenen")] Opdracht opdracht, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { try { if (ModelState.IsValid) { string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(file.FileName)); file.SaveAs(path); opdracht.Image = ImageExtension.ConvertImage(path); db.Opdrachten.Add(opdracht); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException Dex) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); return(View("Error", new HandleErrorInfo(Dex, "Opdracht", "Create"))); } catch (FileNotFoundException FNFex) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); return(View("Error", new HandleErrorInfo(FNFex, "Opdracht", "Create"))); } catch (Exception ex) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); return(View("Error", new HandleErrorInfo(ex, "Opdracht", "Create"))); } } else { ViewBag.FileNotSpecifiedErrorMessage = "You have not specified a file."; } return(View(opdracht)); }