我正在尝试使用数据表 - 从 asp.net 代码中用作我的 jquery 自动完成中的源。我很难将我的表格转换为 json 格式。
var resultItems = (from DataRow dr in dt.AsEnumerable()
select new SearchSerialResults
{
BeingSearched = (string)dr["BeingSearched"],
G017 = (string)dr["G017"],
G036 = (string)dr["G036"],
E017 = (string)dr["E017"]
}).ToList();
var jsonObject = new
{
total = totalPages,
pageSize,
records = totalRecords,
rows = (from SearchSerialResults item in resultItems
select new
{
id = item.G017,
cell = new[]
{
item.ContractLineItem.ToString(),
item.BeingSearched,
item.G017,
item.G036,
item.E017,
""
}
}).ToArray()
};
return Json(jsonObject) // for MVC