public ActionResult Create(Photos photo, IEnumerable <HttpPostedFileBase> files) { if (!ModelState.IsValid) { return(View(photo)); } if (files.Count() == 0 || files.FirstOrDefault() == null) { ViewBag.error = "Please Choose a fi9le to upload !"; return(View(photo)); } // int typeid= photo.PhotoId; var model = new Photos(); foreach (var file in files) { if (file.ContentLength == 0) { continue; } model.UserName = photo.UserName; model.Description = photo.Description; var fileName = Guid.NewGuid().ToString(); var extension = System.IO.Path.GetExtension(file.FileName).ToLower(); using (var img = System.Drawing.Image.FromStream(file.InputStream)) { model.ThumbPath = String.Format("/GalleryImages/thumbs/{0}{1}", fileName, extension); model.ImagePath = String.Format("/GalleryImages/{0}{1}", fileName, extension); // Save thumbnail size image, 100 x 100 SaveToFolder(img, fileName, extension, new Size(100, 100), model.ThumbPath); // Save large size image, 800 x 800 SaveToFolder(img, fileName, extension, new Size(600, 600), model.ImagePath); } // model.PhotoId = typeid; galRepo.Upload(model); } return(RedirectPermanent("/home")); }