public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var entity = await _dbContext.Products.FindAsync(Id); if (entity == null) { return(NotFound()); } if (ProductModel.ImageFile != null && ProductModel.ImageFile.Length > 0) { _fileUploader.Delete(entity.ImageUrl); ProductModel.ImageUrl = await _fileUploader.Upload(ProductModel.ImageFile, "products"); } //Bind properties entity.Name = ProductModel.Name; entity.Description = ProductModel.Description; entity.IsFeatured = ProductModel.IsFeatured; entity.Price = ProductModel.Price; entity.ImageUrl = ProductModel.ImageUrl; await _dbContext.SaveChangesAsync(); return(RedirectToPage("Index")); }