public ActionResult Create([Bind(Exclude = "Picture")] Product model, HttpPostedFileBase picture) { if (ModelState.IsValid) { if (picture != null) { if (picture.ContentLength > (4 * 1024 * 1024)) { ModelState.AddModelError("", "Image must not be greater than 4MB"); return(View(model)); } if (!(picture.ContentType == "image/jpeg" || picture.ContentType == "image/png")) { ModelState.AddModelError("", "Image must be either Jpeg or PNG"); return(View(model)); } model.Picture = new byte[picture.ContentLength]; picture.InputStream.Read(model.Picture, 0, picture.ContentLength); } else { ModelState.AddModelError("", "Image is Needed for the product"); return(View(model)); } _repo.CreateProduct(model); return(RedirectToAction("Index")); } ModelState.AddModelError("", "Error Occured try again."); return(View(model)); }