“No records to display” in Telerik's TreeList

亡梦爱人 提交于 2019-12-11 19:15:46

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/36264899/no-records-to-display-in-teleriks-treelist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!