asp.net – 无法返回JsonResult
发布时间:2020-09-19 07:04:32 所属栏目:asp.Net 来源:互联网
导读:以下查询已成功运行. var tabs = ( from r in db.TabMasters orderby r.colID select new { r.colID, r.FirstName, r.LastName }) .Skip(rows * (page - 1)
|
以下查询已成功运行. var tabs = (
from r in db.TabMasters
orderby r.colID
select new { r.colID,r.FirstName,r.LastName })
.Skip(rows * (page - 1)).Take(rows);
现在我想要返回JsonResult var jsonData = new
{
total = (int)Math.Ceiling((float)totalRecords / (float)rows),page = page,records = totalRecords,rows = (from r in tabs
select new { id = r.colID,cell = new string[] { r.FirstName,r.LastName } }).ToArray()
};
return Json(jsonData,JsonRequestBehavior.AllowGet);
但它会给我一个错误,如: 我该怎么做才能得到预期的结果? 解决方法我怀疑它就像使用AsEnumerable()将最后一部分推入进程内查询一样简单:var jsonData = new
{
total = (int)Math.Ceiling((float)totalRecords / (float)rows),rows = (from r in tabs.AsEnumerable()
select new { id = r.colID,cell = new[] { r.FirstName,r.LastName } }
).ToArray()
};
return Json(jsonData,JsonRequestBehavior.AllowGet);
为清楚起见,您可能希望从匿名类型初始化程序中提取该查询: var rows = tabs.AsEnumerable()
.Select(r => new { id = r.colID,r.LastName })
.ToArray();
var jsonData = new {
total = (int)Math.Ceiling((float)totalRecords / (float)rows),page,rows
}; (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 谈基于.net平台开发中的模式窗体
- asp.net-mvc – 所有请求获取HTTP错误401.2 – 未经授权的响
- asp.net – 304未修改静态文件
- IIS 7中为ASP.NET缺少MIME类型404.17
- ASP.NET通过分布式Session提升性能
- asp.net-mvc – ASP.NET MVC中的WebApi [FromUri]是什么?
- asp.net-mvc – MVC 3布局页面,Razor模板和下拉列表
- asp.net – 什么时候Response.IsClientConnected慢?
- asp.net – 菜单控件生成的js导致Web窗体中的Sys未定义的异
- ASP.NET TextBox LostFocus事件
