public ActionResult Create(mYimage m, HttpPostedFileBase img) { if (ModelState.IsValid) { if (img != null) { img.SaveAs(HttpContext.Server.MapPath("~/Uploads/") + img.FileName); m.Image = img.FileName; } else if (img == null) { if (TempData["tmp"] == null) { m.Image = "default.jpg"; } else { m.Image = TempData["tmp"].ToString(); } } } if (m.imageId > 0) { db.Entry(m).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { db.mYimages.Add(m); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
public ActionResult Create(int id = 0) { mYimage tb = new mYimage(); if (id > 0) { tb = db.mYimages.Find(id); } TempData["tmp"] = tb.Image; return(View(tb)); }