I have an mvc 5 application in which a product has one or many images.in the create form, i want to upload images for product before save it.
I'm trying to use a temp folder to save images and once a product is saved, we save images in database, but i don't think it's the best solution
public ActionResult ProductPictureAdd(int pictureId, int productId)
{
if (pictureId == 0)
throw new ArgumentException();
var product = _productService.GetById(productId);
if (product == null)
throw new ArgumentException("No product found with the specified id");
if (_workContext.CurrentUser != null && product.UserId != _workContext.CurrentUser.ID)
return RedirectToAction("List");
_productService.InsertProductPicture(new ProductPicture
{
PictureId = pictureId,
ProductId = productId,
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow
});
return Json(new { Result = true }, JsonRequestBehavior.AllowGet);
}