public ActionResult Create(Product product, HttpPostedFileBase uploadImage) { if (ModelState.IsValid && uploadImage != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(uploadImage.InputStream)) { imageData = binaryReader.ReadBytes(uploadImage.ContentLength); } product.Image = imageData; db.Products.Add(product); db.SaveChanges(); return RedirectToAction("Index"); } return View(product); }
public ActionResult Edit(Product product,HttpPostedFileBase uploadImage) { if (ModelState.IsValid && uploadImage!=null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(uploadImage.InputStream)) { imageData = binaryReader.ReadBytes(uploadImage.ContentLength); } product.Image = imageData; db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", product.CategoryId); return View(product); }