I am writing a very small application with mvc4 and entity framework 5.
I want to add a product and store and image for the product.
I have a model
Try to fix like that:
1 . Replace
<input name="Image" type="file"/>
with <input name="ImageFile" type="file"/>
2 . In controller:
[HttpPost]
public ActionResult Create(CatalogItemModel catalogitemmodel, HttpPostedFileBase ImageFile)
{
using (var ms = new MemoryStream())
{
ImageFile.InputStream.CopyTo(ms);
catalogitemmodel.Image = ms.ToArray();
}
if (ModelState.IsValid)
{
db.CatalogItemModels.Add(catalogitemmodel);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(catalogitemmodel);
}