Here is my Create Method
这是我的创建方法
/* [HttpPost]
public ActionResult Create(Image newRecipe)
{
try
{
using (var db = new MitishaKitchenContext())
{
db.Images.Add(newRecipe);
db.SaveChanges();
}
return RedirectToAction("Index");
}
catch { return View(); }
}*/
[HttpPost]
public ActionResult Create(Image IG)
{
// Apply Validation Here
if (IG == null)
{
return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest);
}
if (IG != null && IG.File.ContentLength > (2 * 1024 * 1024))
{
ModelState.AddModelError("CustomError", "File size must be less than 2 MB");
return View();
}
if (!(IG.File.ContentType == "image/jpeg" || IG.File.ContentType == "image/gif"))
{
ModelState.AddModelError("CustomError", "File type allowed : jpeg and gif");
return View();
}
// IG.FileName = IG.File.FileName;
// IG.ImageSize = IG.File.ContentLength;
byte[] data = new byte[IG.File.ContentLength];
IG.File.InputStream.Read(data, 0, IG.File.ContentLength);
IG.ImageData = data;
using (MitishaKitchenContext dc = new MitishaKitchenContext())
{
dc.Images.Add(IG);
dc.SaveChanges();
}
return RedirectToAction("Index");
}
/* [Ht