【发布时间】:2015-09-16 16:42:57
【问题描述】:
您好,我一直在尝试将 dataTable 用于 ASP.net 中的一个项目,但我遇到了一堵墙,我想在其中从 sql 数据库传递到 aadata 字符串格式,我设法获得了 LINQ 查询,它是以下:
var querytable4 = from table1 in db.ScrapClassifications
join table2 in db.ScrapGroups on table1.idGroup equals table2.idGroup
join table3 in db.ProdAreas on table1.idArea equals table3.idArea
join table4 in db.ScrapSubGroups on table1.idSubGroup equals table4.idSubGroup
select new {ActiveBool = table1.Active,
idScrap= table1.idScrapClassification,
Area= table3.Area,
groupDesc= table2.Description,
subgroupdesc=table4.Description,
description=table1.Description
};
它似乎可以正确显示所有值,然后使用 Newtonsoft 序列化程序我尝试执行以下操作:
var json = JsonConvert.SerializeObject(querytable4);
它会抛出以下输出:
[{\"ActiveBool\":true,\"idScrap\":1,\"Area\":\"Controllers\",\"groupDesc\":...
我的 ajaxhandler 如下:
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = 100,
iTotalDisplayRecords = 100,
aaData = json
},JsonRequestBehavior.AllowGet);
只接受以下格式:
public class HomeController : Controller
{
public ActionResult AjaxHandler(jQueryDataTableParamModel param)
{
return Json(new{
sEcho = param.sEcho,
iTotalRecords = 97,
iTotalDisplayRecords = 3,
aaData = new List<string[]>() {
new string[] {"1", "Microsoft", "Redmond", "USA"},
new string[] {"2", "Google", "Mountain View", "USA"},
new string[] {"3", "Gowi", "Pancevo", "Serbia"}
}
},
JsonRequestBehavior.AllowGet);
}
}
无论如何要进行这种转换?我被困了一个星期只是想弄清楚这一点,我的数据库也包含布尔值和其他数值,我也尝试创建一个字符串列表,但是当我尝试进行转换时,它告诉我一些值是我的查询中没有字符串..
【问题讨论】:
标签: asp.net ajax linq datatable