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