Parent and child datatable C#

Parent and child datatable C#

raiskyzyraiskyzy Posts: 2Questions: 1Answers: 1
edited January 24 in Free community support

Link to test case:
https://live.datatables.net/xocalozo/1/edit

Error messages shown:

jquery.dataTables.min.js:4 Uncaught TypeError: Cannot read properties of undefined (reading 'length')
at jquery.dataTables.min.js:4:48531
at Object.e [as success] (jquery.dataTables.min.js:4:25877)
at c (jquery.min.js:2:28327)
at Object.fireWith [as resolveWith] (jquery.min.js:2:29072)
at l (jquery.min.js:2:79901)
at XMLHttpRequest.<anonymous> (jquery.min.js:2:82355)

Description of problem:

I'm trying to perform similar functionality as described in this article https://datatables.net/forums/discussion/53548/parent-child-datatables, https://live.datatables.net/cirelube/1/edit but in my case it doesn't work.
This method ajax: "/employee/home/getCustomersList" returns the complete list of clients,

[HttpGet]
public IActionResult GetCustomersList(string id)
{
    List<Customers> objCustomersList = _unitOfWork.Customers.GetAll().ToList(); //includeProperties: "Branches"
    return Json(new { data = objCustomersList });
}

when selecting one of the lines, it is necessary for data on the client’s accounts to appear, 
url: "/employee/home/getAccountsData"

public IActionResult GetAccountsData()
{  
    var model = _context.Customers.Take(10)
        .Select(customer => new
        {
            CIF = customer.CIF,
            Accounts = _context.Accounts.Where(o => o.CIF == customer.CIF).Take(5).ToList()
        }).ToList();

    return Json(new { data = model });
}

but it does not appear
Apparently I'm calling the GetAccountsData method incorrectly

please assist

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,082Questions: 26Answers: 4,908

    Your test case doesn't run properly to show the error you are getting. Its hard to say what the problem might be without seeing ir.

    Searching the forum for that error it seems the problem might be with the JSON response. Use the browser's network inspector to see the JSON response. What do you find. Maybe post it here and use Markdown ode formatting with the triple ticks (```) on new lines before and after the code block.

    Kevin

  • raiskyzyraiskyzy Posts: 2Questions: 1Answers: 1
    Answer ✓

    Dears,

    Please close the discussion

    I found the problem, the problem was in the method that JSON conveyed
    Thanks for the tip :)

Sign In or Register to comment.