几天来,我一直在努力尝试用我的 ASP.Net 应用程序实现 jQuery Bootgrid。到目前为止,这就是我所拥有的:(按功能排序还没有工作,我稍后会解决)
public JsonResult IndexJson(RequestData model)
{
var result = (from x in db.ContactSet
select new
{
x.AccountId,
x.FirstName,
x.LastName,
x.FullName,
x.JobTitle,
x.ParentCustomerId,
x.EMailAddress1,
x.Telephone1,
x.MobilePhone,
x.Fax,
x.GenderCode,
x.BirthDate
}); //? Gets all rows
result = (from x in result
where x.FirstName.Contains(model.searchPhrase)
|| x.LastName.Contains(model.searchPhrase)
select x); //? Search Filter
var totalRows = result.Count(); //? Sets totalRows (for ResponseData)
if (model.rowCount == -1)
model.rowCount = totalRows; //? In case View All Rows is selected by Bootgrid (for ResponseData)
// TODO: Add Order By functionality
var tResult = new ResponseData<object>()
{
current = model.current,
rowCount = model.rowCount,
rows = result.ToList(),
total = totalRows
}; //? Builds Json Response
return Json(tResult, JsonRequestBehavior.AllowGet);
}
这段代码的问题是我需要在搜索功能之后计算记录总数,而我只是不擅长正确使用 LINQ 查询。
当我到达时,var totalRows = result.Count();
我收到以下错误:
System.NotSupportedException: '方法'Where'不能遵循方法'Select'或不受支持。尝试根据支持的方法编写查询,或者在调用不受支持的方法之前调用“AsEnumerable”或“ToList”方法。
知道这里有什么问题吗?