我正在尝试在JQGrid中显示IEnumerable int值。如下所示,列gmu是IEnumerable int但在网格中没有正确显示。而不是值,这是gmu列的网格中显示的内容:
System.Linq.Enumerable + WhereSelectEnumerableIterator 2[<>f__AnonymousType2
5 [System.Int32,System.String,System.Int32,System.Int32,System.Int32],System.Int32]
var result = from x in test
group x by new { x.dau, x.population_estimate, x.year } into p
select new
{
dau = p.Key.dau,
population_estimate = p.Key.population_estimate,
year = p.Key.year,
gmu = p.Select(x => x.gmu)
};
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = results.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var pageResults = result.Skip(pageIndex * pageSize).Take(pageSize);
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = (
from pageResult in pageResults
select new
{
//id = pageResult.id,
cell = new[] {
pageResult.year.ToString(),
pageResult.dau.ToString(),
pageResult.gmu.ToString(),
pageResult.population_estimate.ToString(),
}
}).ToArray()
};
答案 0 :(得分:1)
您只需在Linq语句中的“选择”之后添加“ToArray()”。
gmu = String.Join<int>(", ", p.Select(x => x.gmu))
正在发生的事情是,当它呈现你的IEnumerable对象时,.NET隐式调用“ToString()”函数(它不够聪明,无法主动枚举对象),导致你看到的