asp.net – 无法返回JsonResult
发布时间:2020-09-12 16:03:12 所属栏目: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 }; (编辑:鲜蔬坊站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-web-api – ASP身份OAuth令牌 – 我应该在移动应用
- asp.net-mvc – 如何在asp.net中使用mvc构建购物车?
- ASP.NET MVC删除操作方法中的查询字符串
- asp.net-mvc – 如何组合两个dataTextFields的SelectList描
- asp-classic – 从Classic ASP执行存储过程
- asp.net – “2015年4月20日Google帐户的OpenID2已经消失”
- asp.net-mvc-4 – WepApi控制器是否应该返回viewmodels
- asp.net-mvc – 值不能为空或为空.参数名称:contentPath
- asp.net-mvc – 应用程序服务层作为静态类
- asp.net-mvc – MVC 5:Asp.net身份:如何建模UserRole
推荐文章
站长推荐
- asp.net – 什么是system.globalization它和本地
- asp.net – 如何设置显示内联的Div元素的固定宽度
- asp.net – 将Eval参数从ASPX文件传递给JavaScri
- RSS2.0中文规范详解及示例
- asp.net-mvc-3 – 应该使用HTTP引用来验证还是令
- asp.net – 如何使用JwtSecurityTokenHandler和J
- asp.net – MVC 4导出到CSV – 另存为对话框在Ch
- asp.net-core – 如何在Visual Studio 2015 RC中
- 服务器端ASP.Net Ajax异常处理
- ASP.NET MembershipProvider加密/解密
热点阅读