public ActionResult Create(ProductImage productimage, IEnumerable <HttpPostedFileBase> images) { if (ModelState.IsValid) { foreach (HttpPostedFileBase img in images) { string imageName = System.IO.Path.GetFileName(img.FileName); img.SaveAs(Server.MapPath("~/Images/" + imageName)); productimage.FKProductId = (int)TempData["productId"]; productimage.ImageName = imageName; productimage.ImagePath = "/Images/" + imageName; objProductImageBO.InsertImage(productimage); } return(RedirectToAction("Index", new { id = productimage.FKProductId })); } return(View(productimage)); }
public ActionResult Create(Product product, IEnumerable <HttpPostedFileBase> images) { ProductImage objProductImage = new ProductImage(); if (ModelState.IsValid) { objProductBO.InsertProduct(product); foreach (HttpPostedFileBase img in images) { string imageName = System.IO.Path.GetFileName(img.FileName); img.SaveAs(Server.MapPath("~/Images/" + imageName)); objProductImage.FKProductId = product.PKProductId; objProductImage.ImageName = imageName; objProductImage.ImagePath = "/Images/" + imageName; objProductImageBO.InsertImage(objProductImage); } return(RedirectToAction("Index")); } ViewBag.FKCategoryId = new SelectList(objCategoryBO.GetCategories(true), "PKCategoryId", "CategoryName"); ViewBag.FKSubCategoryId = new SelectList(objSubCategoryBO.GetSubCategories(0, true), "PKSubCategoryId", "SubCategoryName"); return(View(product)); }