public ActionResult AddPhotoToActorPost(int id) { var actor = _actorDataProvider.GetActorDetailsPhotosAndMovies(id); if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { var fileName = Helper.GetRandomCharacters() + actor.Name + Path.GetFileName(file.FileName); actor.PhotoUrl = Path.Combine( Server.MapPath(actor.Folder), fileName); file.SaveAs(actor.PhotoUrl); } for (var i = 0; i < Request.Files.Count; i++) { var f = Request.Files[i]; if (f.ContentLength > 0) { var fileName = Helper.GetRandomCharacters() + actor.Name + Path.GetFileName(f.FileName); actor.Photos.Add(new PhotoPathDto() { Path = Path.Combine( Server.MapPath(actor.Folder), fileName) }); f.SaveAs(Path.Combine( Server.MapPath(actor.Folder), fileName)); } } _actorService.AddPhotosToActor(actor); return(RedirectToAction("Index")); } else { var addPhotoToActorViewModel = new AddPhotoToActorViewModel() { Actor = actor }; return(View(addPhotoToActorViewModel)); } }