public ActionResult Create(Photo photo, HttpPostedFileBase image) { photo.CreatedDate = DateTime.Today; if (!ModelState.IsValid) { return View("Create", photo); } else { if (image != null) { photo.ImageMimeType = image.ContentType; photo.PhotoFile = new byte[image.ContentLength]; image.InputStream.Read(photo.PhotoFile, 0, image.ContentLength); } context.Add<Photo>(photo); //context.Photos.Add(photo); context.SaveChanges(); return RedirectToAction("Index"); } }
public ActionResult Create() { Photo newPhoto = new Photo(); newPhoto.CreatedDate = DateTime.Today; return View("Create", newPhoto); }