public ActionResult Create(ProfessionalDocumentsViewModel model) { if (ModelState.IsValid) { var DocumentToAdd = new ProfessionalDocuments(); DocumentToAdd.Title = model.Title; DocumentToAdd.Description = model.Description; DocumentToAdd.Icon = model.Icon; if (model.FileUpload != null && model.FileUpload.ContentLength > 0) { var uploadDir = "~/DocumentUploads/"; var imagePath = Path.Combine(Server.MapPath(uploadDir), model.FileUpload.FileName); var documentURL = Path.Combine(uploadDir, model.FileUpload.FileName); documentURL = documentURL.Replace(@"\", "/"); imagePath = imagePath.Replace(@"\", "/"); model.FileUpload.SaveAs(imagePath); DocumentToAdd.FileURL = documentURL; } db.ProfessionalDocuments.Add(DocumentToAdd); db.SaveChanges(); return(RedirectToAction("DocumentPortfolio")); } return(View(model)); }
// GET: ProfessionalDocuments/Create public ActionResult Create() { var model = new ProfessionalDocumentsViewModel(); return(View(model)); }