public ActionResult Upload(ImageTable IT) { if (IT.File.ContentLength > (4 * 1024 * 1024)) { ModelState.AddModelError("CustomError", "File size must be less than 4MB"); return View(IT); } if (!(IT.File.ContentType == "image/jpeg" || IT.File.ContentType == "image/gif")) { ModelState.AddModelError("CustomError", "File type allowed: jpeg and gif"); } IT.FileName = IT.File.FileName; IT.ImageSize = IT.File.ContentLength; byte[] data = new byte[IT.File.ContentLength]; IT.File.InputStream.Read(data, 0, IT.File.ContentLength); IT.ImageData = data; using (PostsDataBaseEntities dc = new PostsDataBaseEntities()) { dc.ImageTables.Add(IT); dc.SaveChanges(); } return RedirectToAction("ImageFetching"); }
public ActionResult ImageFetching() { List<ImageTable> listAll = new List<ImageTable>(); using (PostsDataBaseEntities dc = new PostsDataBaseEntities()) { listAll = dc.ImageTables.ToList(); } return View(listAll); }