コード例 #1
0
        public ActionResult UploadPhoto(Photo photo, HttpPostedFileBase image)
        {
            if (!ModelState.IsValid)
            {
                if (image == null)
                {
                    return(View(photo));
                }
                return(View(photo));
            }
            photo.PhotoUrl   = "~/GalleryPhotos/" + image.FileName;
            photo.UploadDate = DateTime.Now;
            photo.PhotoId    = Guid.NewGuid();
            Dal.AddNewPhoto(photo.Transform());

            image.SaveAs(Path.Combine(Server.MapPath("~/GalleryPhotos"), image.FileName));
            return(RedirectToAction("Index"));
        }