错误:LINQ to Entities 无法识别该方法
我正在尝试构建一个jqgrid。服务器代码返回错误?:
LINQ to Entities 无法识别“System.String ToString()”方法,并且此方法无法转换为存储表达式。
代码:
public ActionResult GridData(string sidx, string sord, int page, int rows)
{
ProductsEntities4 db = new ProductsEntities4();
var jsondata = new {
total = 1,
page = 1,
records = 2,
rows = (from pr in db.Products
select new {
i = pr.Id,
cell = new string[] { pr.Id.ToString(), pr.ProductName }
}).ToArray()
};
//return jsondata;
return Json(jsondata, JsonRequestBehavior.AllowGet);
}
哪里
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#list").jqGrid({
url: '/Home/GridData/',
datatype: 'json',
mtype: 'GET',
colNames: ['Id', 'ProductName'],
colModel: [
{ name: 'Id', index: 'Id', width: 40, align: 'left' },
{ name: 'ProductName', index: 'ProductName', width: 40, align: 'left' }],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/coffee/images',
caption: 'My first grid'
});
});
i am trying to build a jqgrid. the server code is returning an error?:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
code:
public ActionResult GridData(string sidx, string sord, int page, int rows)
{
ProductsEntities4 db = new ProductsEntities4();
var jsondata = new {
total = 1,
page = 1,
records = 2,
rows = (from pr in db.Products
select new {
i = pr.Id,
cell = new string[] { pr.Id.ToString(), pr.ProductName }
}).ToArray()
};
//return jsondata;
return Json(jsondata, JsonRequestBehavior.AllowGet);
}
where
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#list").jqGrid({
url: '/Home/GridData/',
datatype: 'json',
mtype: 'GET',
colNames: ['Id', 'ProductName'],
colModel: [
{ name: 'Id', index: 'Id', width: 40, align: 'left' },
{ name: 'ProductName', index: 'ProductName', width: 40, align: 'left' }],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/coffee/images',
caption: 'My first grid'
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用此代码
并从 jqGrid 中删除已弃用的
imgpath
参数。Try with this code
and remove deprecated
imgpath
parameter from the jqGrid.