public ActionResult UploadImageMethod() { if (Request.Files.Count != 0) { for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase file = Request.Files[i]; int fileSize = file.ContentLength; string fileName = file.FileName; file.SaveAs(Server.MapPath("~/Content/photos/" + fileName)); PhotoGallery photoGallery = new PhotoGallery(); photoGallery.PhotoID = Guid.NewGuid(); photoGallery.Name = fileName; photoGallery.PhotoPath = "~/Content/photos/" + fileName; db.PhotoGalleries.Add(photoGallery); db.SaveChanges(); } return Content("Success"); } return Content("failed"); }
public ActionResult PhotoGallery() { var photosModel = new PhotoGallery(); var photoFiles = Directory.GetFiles(Server.MapPath("~/Content/photos")); foreach (var item in photoFiles) { photosModel.PhotoList.Add(Path.GetFileName(item)); } return View(photosModel); }