Im trying to us a controller in MVC2 to upload a file but i get an object reference not set to an instance of an object error
[HttpPost]
public ActionResult AddPhoto(int id, FormCollection formValues, HttpPostedFile image, AlbumPhotos photo )
{
AlbumPhoto photos = new AlbumPhoto();
UserPhotoAlbum album = AlbumRepo.GetAlbum(id);
photo.AlbumId = id;
photos.AlbumId = photo.AlbumId;
photo.PostedDate = DateTime.Now;
photos.PostedDate = photo.PostedDate;
album.LastUpdate = photo.PostedDate;
if (image.FileName != null)
{
photo.PhotoMimeType = image.ContentType;
photos.PhotoMimeType = image.ContentType;
photo.PhotoData = new byte[image.ContentLength];
photos.PhotoData = photo.PhotoData;
image.InputStream.Read(photo.PhotoData, 0, image.ContentLength);
photo.PhotoUrl = "../../Content/UserPhotos/" + image.FileName;
photos.PhotoUrl = photo.PhotoUrl;
image.SaveAs(Server.MapPath("~/Content/UserPhotos/" + image.FileName));
}
AlbumRepo.AddPhotoToAlbum(photos);
AlbumRepo.Save();
return RedirectToAction("Album", new { id = photo.AlbumId });
}
Please tell me if i'm doing something wrong.