Reputation: 749
I'm trying to display IEnumerable int values in JQGrid. As seen below column gmu is IEnumerable int but does not show correctly in the grid. Instead of the values, this is what shows in the grid for that gmu column:
System.Linq.Enumerable+WhereSelectEnumerableIterator2[<>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()
};
Upvotes: 0
Views: 452
Reputation: 102783
You just need to add "ToArray()" after "Select" in your Linq statement.
gmu = String.Join<int>(", ", p.Select(x => x.gmu))
What's happening is that, when it goes to render your IEnumerable object, .NET is implicitly invoking the "ToString()" function (it's not smart enough to actually enumerate the object on its own initiative), resulting in what you see.
Upvotes: 1