Yurii N.
Yurii N.

Reputation: 5703

"No records to display" in Telerik's TreeList

I have simple TreeList, which I want to be filled up with some values. My TreeList:

@(Html.Kendo().TreeList<Book>()
            .Name("BooksTreeList")
            .Columns(columns =>
            {
                columns.Add().Field(c => c.BookName);
                columns.Add().Field(c => c.BookAuthor);
            })
            .Filterable()
            .Sortable()
            .DataSource(dataSource => dataSource
                .Read(read => read.Action("ReadAllBooks", "Catalog"))
                .ServerOperation(false)
                .Model(m =>
                {
                    m.Id(c => c.BookId);
                    m.ParentId(c => c.ParentId);
                    m.Expanded(true);
                    m.Field(x => x.BookId);
                    m.Field(x => x.BookAuthor);
                })
            ))

And my controller class:

public async Task<IActionResult> ReadAllBooks([DataSourceRequest] DataSourceRequest request)
{
    var result = (await GetAllBooks())
      .ToTreeDataSourceResult(
      request,
      x => x.BookId,
      x => x.ParentId);
    return Json(result);
}
private async Task<List<BookViewModel>> GetAllBooks()
{
   return await _dbContext.Books.Select(x => new BookViewModel()
   {
      BookId = x.CodingId,
      BookName = x.BookName,
      BookAuthor = x.BookAuthor,
      ParentId = x.ParentId
   }).ToListAsync();
}

But when I'm entering the page, my treelist always shows "No records to display" even if I have records, I checked it with the help of the debugger. How should I fill my TreeList correctly?

Upvotes: 0

Views: 1373

Answers (1)

Daniil
Daniil

Reputation: 46

I have same error then I use Guid.Empty for Root elements. Root elements should have ParentId is NULL. Try to use Guid? instead of guid, and assign to it NULL.

link: http://www.telerik.com/forums/no-records-to-display-959da9677068

Upvotes: 3

Related Questions