Bloente`enter image description herenamespace believe.Controllers { public class ProductController : Controller { private readonly IUnitOfWork _context; private readonly IWebHostEnvironment _hostEnvironment; public ProductController(IUnitOfWork context, IWebHostEnvironment hostEnvironment) { _context = context; _hostEnvironment = hostEnvironment; }
public IActionResult Index() { return View(); } //GET public IActionResult Delete(int? id) { if (id is null or 0) { return NotFound(); } var obj = _context.Product.GetFirstOrDefault(c => c.Id == id); return View(obj); } [HttpPost] public IActionResult DeletePOST(int? id) { var obj = _context.Product.GetFirstOrDefault(c => c.Id == id); if (obj == null) { return NotFound(); } _context.Product.Remove(obj); _context.Save(); TempData["success"] = "Category deleted successfully"; return RedirectToAction("Index"); } public IActionResult UpSert(int? id) { //Product product = new(); //IEnumerable < SelectListItem > CategoryList = _context.Category.GetAll().Select(u=>new SelectListItem { Text = u.Name, Value = u.Id.ToString() }); // IEnumerable<SelectListItem> CoverTypeList = _context.CoverType.GetAll().Select(u => new SelectListItem { Text = u.Name, Value = u.Id.ToString() }); ProductVM productVM = new() { Product = new(), CategoryList = _context.Category.GetAll().Select(u => new SelectListItem { Text = u.Name, Value = u.Id.ToString() }), CoverTypeList = _context.CoverType.GetAll().Select(u => new SelectListItem { Text = u.Name, Value = u.Id.ToString() }) }; if (id is null or 0) { //create product //ViewBag.CategoryList = CategoryList; //ViewBag.CoverTypeList = CoverTypeList; return View(productVM); } else { //update product } ; return View(productVM); } [HttpPost] public IActionResult UpSert(ProductVM obj, IFormFile? file) { if(ModelState.IsValid) { string wwwRootPath = _hostEnvironment.WebRootPath; if(file !=null) { string fileName = Guid.NewGuid().ToString(); var uploads = Path.Combine(wwwRootPath, @"images\products"); var extension = Path.GetExtension(file.FileName); using(var fileStreams = new FileStream(Path.Combine(uploads, fileName + extension),FileMode.Create)) { file.CopyTo(fileStreams); } obj.Product.ImageUrl = @"\images\products" + fileName + extension; }
_context.Product.Add(obj.Product); _context.Save(); TempData["success"] = "Product update successfully"; return RedirectToAction("Index"); } return View(obj); } #region API CALLS [HttpGet] public IActionResult GetAll() { var productList = _context.Product.GetAll(); return Json(productList); } #endregion
r code hereckquote`
changed the return as you have showing but the pagge saying loading but it never load
[first screen shot of the controller][2secon screen shot\I'm new to coding world I'm trying to load my data form my database using DataTables, but for some reason I keep getting this error message. What am I doing wrong?



Trying to load the data from my database but it seems like my configuration is not working

