我想用员工列表填充剑道网格。当我将员工列表直接发送到网格时,网格会填充。当我稍微操纵列表时,网格是空的。员工类有一个我需要操作的布尔“选定”字段。在这两种情况下,在调试器中停止控制器时,列表都有 600 名员工,所以数据就在那里。
这是视图中的代码(我什至没有绑定到“选定”属性 - 认为这可能是问题所在)
@(Html.Kendo().Grid<TRS.MVC.Models.SelectEmployeeModel>()
.Name("gridEmployee")
.HtmlAttributes(new { style = "height: 300px" })
.Columns(columns =>
{
columns.Bound(p => p.CompanyCode).Width(100);
columns.Bound(p => p.EmployeeCode).Width(100);
columns.Bound(p => p.EmployeeName).Width(100);
})
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Single))
.Navigatable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetEmployees", "EmployeeSelectDlg"))
)
)
这是有效的代码
public ActionResult GetEmployees([DataSourceRequest]DataSourceRequest request)
{
List<SelectEmployeeModel> employeesForGrid;
employeesForGrid = (from e in trs.Employees select e).ToList();
return Json(employeesForGrid.ToDataSourceResult(request));
}
以及不起作用的代码(网格为空)。在这两种情况下,当在调试器中停止时,“employeesForGrid”都有 600 个项目。
public ActionResult GetEmployees([DataSourceRequest]DataSourceRequest request)
{
List<Employee> jobEmployees;
List<SelectEmployeeModel> employeesForGrid;
Job selectedJob = (from j in trs.Jobs.Include("JobEmployees") where j.JobKey == selectedJobKey select j).First();
if (selectedJob.JobEmployees.Any())
jobEmployees = (from j in selectedJob.JobEmployees select j).Select(eq => eq.Employee).ToList();
else
jobEmployees = new List<Employee>();
employeesForGrid = (from e in trs.Employees select new SelectEmployeeModel() { Employee = e, Selected = jobEmployees.Contains(e) }).ToList();
return Json(employeesForGrid.ToDataSourceResult(request));
}
没有错误消息只是一个空的网格。