public ActionResult Create(ItemViewModel item) { try { if (item.Photo != null) { if (item.Photo.Length > 0) { byte[] p1 = null; using (var fs1 = item.Photo.OpenReadStream()) using (var ms1 = new MemoryStream()) { fs1.CopyTo(ms1); p1 = ms1.ToArray(); } DbContext _context = HttpContext.RequestServices.GetService(typeof(DbContext)) as DbContext; Item newItem = new Item() { Name = item.Name, Category = item.Category, Description = item.Description, Photo = p1, Price = item.Price }; _context.AddItem(newItem); item.PhotoBytes = p1; return(View("Details", item)); } } return(View("Create", item)); } catch { return(View()); } }