public class StudentController : Controller
{
private read-only IStudentService _studentService;
public StudentController(IStudentService studentService)
{
_studentService = studentService;
}
public IActionResult Index()
{
return View();
}
public IActionResult Read([DataSourceRequest] DataSourceRequest request)
{
//How to use the DynamiclinqCore here
// GetAll retuns billions of records
return Json(_studentService.GetAll().ToDataSourceResult(request));
}
}
查看:
<script>
$(function() {
$("#grid").kendoGrid({
dataSource: {
transport: {
read: {
url: "@Url.Action("Read", "Student")",
dataType: 'json',
contentType: "application/json",
type: "POST"
},
parameterMap: function (data, options) {
debugger;
return JSON.stringify(options);
}
},
schema: {
data: "Data",
total: "Total",
model: {
id: "StudentID",
fields: {
StudentID: { editable: false, nullable: true },
StudentName: { editable: false },
ParentID: { editable: false }
}
}
},
pageSize: 1000,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
filterable: true,
sortable: true,
pageable: true,
height: 500,
columns: [
{ field: "StudentID", width: "150px" },
{ field: "StudentName", width: "250px" },
{ field: "ParentID", width: "250px" }
]
});
});
</script>
<div id="grid"></div>
这是我的服务
public class StudentService : IStudentService
{
private readonly CBDBDataContext _context;
public StudentService(CBDBDataContext context)
{
_context = context;
}
public IEnumerable<Student> GetAll()
{
return _context.Students.ToList();
}
}