public ActionResult AddProduct(Product product, List<ImageUpload> image) { var productRepo = new ProductRepository(Properties.Settings.Default.ConStr); var imageRepo = new ImageRepository(Properties.Settings.Default.ConStr); productRepo.AddProduct(product); List<Image> images = new List<Image>(); foreach (ImageUpload i in image) { var fileName = Guid.NewGuid() + Path.GetExtension(i.Image.FileName); i.Image.SaveAs(Server.MapPath("~/Images/") + fileName); images.Add(new Image { ProductId = product.ProductId, FileName = fileName, }); } imageRepo.AddImage(images); return Redirect("index"); }