[HttpPost] [ValidateAntiForgeryToken] //public async Task<IActionResult> Edit([Bind("ImgID,Title,ImageFile")] IFormFile fileobj, imageModels imgModels, string fileName, int id) public async Task<IActionResult> Edit(imageModels imgModels, int id, IFormFile ImageFile) { var imageModels = await _context.Images.FindAsync(id); if (ImageFile != null) { var imagePath = Path.Combine(_hostEnvironment.WebRootPath, "images", imageModels.ImgName); if (System.IO.File.Exists(imagePath)) System.IO.File.Delete(imagePath); _context.Images.Remove(imageModels); string wwwRootPath = _hostEnvironment.WebRootPath; string fileName = Path.GetFileNameWithoutExtension(imgModels.ImageFile.FileName); string extension = Path.GetExtension(imgModels.ImageFile.FileName); imgModels.ImgName = fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; string path = Path.Combine(wwwRootPath + "/images/", fileName); using (var fileStream = new FileStream(path, FileMode.Create)) { //await imgModels.ImageFile.CopyToAsync(fileStream); imgModels.ImageFile.CopyTo(fileStream); } } _context.Update(imgModels); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); //return View(imgModels); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)