问题
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