public IActionResult OnPost(Core.Whiskey whiskey, int searcharea, IFormFile photo) { if (photo != null) { var path = Path.Combine(IWebHostEnvironment.WebRootPath, "Images", whiskey.Imagedata); System.IO.File.Delete(path); path = Path.Combine(IWebHostEnvironment.WebRootPath, "Images", photo.FileName); var stream = new FileStream(path, FileMode.Create); photo.CopyToAsync(stream); FileName = photo.FileName; whiskey.Imagedata = photo.FileName; //stream.Close(); } whiskeyData.Edit(whiskey, searcharea); return(RedirectToPage("./Index")); }