我想在网格中显示已过滤的数据,但我不知道在monthYearfilter where子句之后它未显示的原因到底是什么原因。它使用currentmonthyear将数据绑定到kendo网格,但不使用monthYearfilter。我以前在不同的项目中使用了相同的功能,并且运行正常。
我确实在linq where子句之后获取DataSourceResult结果中的数据,但是没有在网格中显示。
//控制器代码
[HttpPost]
public ActionResult BillingChecklist_Read([DataSourceRequest]DataSourceRequest request,string monthYearfilter)
{
using (var preemploymentdata = new AREntities())
{
IQueryable<BillingCheckList> preEmploymentWorkflows = preemploymentdata.BillingCheckLists;
DataSourceResult result;
if (monthYearfilter != null)
{
result = preEmploymentWorkflows.Where(x => x.MonthYear == monthYearfilter).ToDataSourceResult(request);
}
else
{
string currentmonthyear = DateTime.Now.Year + "/0" + DateTime.Now.Month;
result = preEmploymentWorkflows.Where(x => x.MonthYear == currentmonthyear).ToDataSourceResult(request);
}
return Json(result);
}
}
//查看代码
@{
Html.Kendo().Grid<BillingCheckList>()
.Name("MyGrid")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("BillingChecklist_Read", "BillingChecklist"))
.Model(model => model.Id(p => p.OfficePrefix))
)
.Columns(col =>
{
col.Bound(o =>.OfficePrefix).Groupable(false).Title("Offices");
col.Bound(o => o.MonthYear).Title("MonthYear").Visible(false);
col.Group(group => group
.Title("Time Entered & Completed").HeaderHtmlAttributes(new { style = "text-align:center" })
.Columns(info =>
{
info.Bound(o => o.IsTimeWk1).HeaderHtmlAttributes(new { style = "text-align:center" }).HtmlAttributes(new { style = "text-align:left" })
.ClientTemplate("<input type='checkbox' #= IsTimeWk1 ? checked='checked': '' # onclick='UpdateCheckBox( #= BilingChecklistID #, \"#= OfficePrefix #\", \"#= 'IsTimeWk1'#\", \"#= IsTimeWk1 #\" )'/>")
.Title("WK<br>1").Width(5);
info.Bound(o => o.IsTimeWk2).HeaderHtmlAttributes(new { style = "text-align:center" }).HtmlAttributes(new { style = "text-align:left" })
.ClientTemplate("<input type='checkbox' #= IsTimeWk2 ? checked='checked': '' # onclick='UpdateCheckBox( #= BilingChecklistID #, \"#= OfficePrefix #\", \"#= 'IsTimeWk2'#\", \"#= IsTimeWk2 #\" )' />")
.Title("WK<br>2").Width(5);
info.Bound(o => o.IsTimeWk3).HeaderHtmlAttributes(new { style = "text-align:center" }).HtmlAttributes(new { style = "text-align:left" })
.ClientTemplate("<input type='checkbox' #= IsTimeWk3 ? checked='checked': '' # onclick='UpdateCheckBox( #= BilingChecklistID #, \"#= OfficePrefix #\", \"#= 'IsTimeWk3'#\", \"#= IsTimeWk3 #\" )'/>")
.Title("WK<br>3").Width(5);
info.Bound(o => o.IsTimeWk4).HeaderHtmlAttributes(new { style = "text-align:center" }).HtmlAttributes(new { style = "text-align:left" })
.ClientTemplate("<input type='checkbox' #= IsTimeWk4 ? checked='checked': '' # onclick='UpdateCheckBox( #= BilingChecklistID #, \"#= OfficePrefix #\", \"#= 'IsTimeWk4'#\", \"#= IsTimeWk4 #\" )'/>")
.Title("WK<br>4").Width(5);
info.Bound(o => o.IsTimeWk5).HeaderHtmlAttributes(new { style = "text-align:center" }).HtmlAttributes(new { style = "text-align:left" })
.ClientTemplate("<input type='checkbox' #= IsTimeWk5 ? checked='checked': '' # onclick='UpdateCheckBox( #= BilingChecklistID #, \"#= OfficePrefix #\", \"#= 'IsTimeWk5'#\", \"#= IsTimeWk5 #\" )'/>")
.Title("WK<br>5").Width(5);
}));
}) .Sortable()
.Render();
}
答案 0 :(得分:0)
由于您要过滤数据服务器端,请在返回DataSourceResult之前尝试清除过滤器,以防止数据在客户端再次被过滤。
result.Filters.Clear();
return Json(result);