在 c# 中向 IEnumerable 添加一列,以便它可以与 WebGrid 一起使用
在此问题中, 添加在 C# 中的 IEnumerable 列 中,我得到以下代码:
var db = Database.Open("LOS");
var ie = db.Query(sqlAssignments);
// make a new ie2 that has an extra calculated field
var ie2 = processes.Select( e => new { e.ACCT, e.RefID, color = e.RefID + 9000000 });
var grid = new WebGrid(ie2.ToList(), rowsPerPage : 50, ajaxUpdateContainerId : "grid" );
数据正确显示,但网格不再排序。如果你通过 ie 而不是 ie2,那就没问题了。无论我是否执行 ToList() 都会出现问题。显然ie和ie2之间有一些区别。 的 GetType
System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object]
这是 ie:和 ie2:
System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Object,<>f__AnonymousType0`10[System.Object,System.Object,System.Object,System.Object,System.Object,System.Object,System.Object,System.Object,System.Object,System.Object]]
:我应该对 ie2 做些什么才能使其与 WebGrid 一起工作并正确排序?
In this question, Add a column to IEnumerable in C#, I got the following code:
var db = Database.Open("LOS");
var ie = db.Query(sqlAssignments);
// make a new ie2 that has an extra calculated field
var ie2 = processes.Select( e => new { e.ACCT, e.RefID, color = e.RefID + 9000000 });
var grid = new WebGrid(ie2.ToList(), rowsPerPage : 50, ajaxUpdateContainerId : "grid" );
The data correctly shows up, however the grid no longer sorts. It sorts fine if you pass ie, instead of ie2. It has the problem if I do the ToList() or not. Obviously there's some difference between ie and ie2. Here's the GetType for ie:
System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object]
and for ie2:
System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Object,<>f__AnonymousType0`10[System.Object,System.Object,System.Object,System.Object,System.Object,System.Object,System.Object,System.Object,System.Object,System.Object]]
What should I do to ie2 to make it work with WebGrid and sort correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试为 ie2 创建类型而不是使用匿名类型,例如:
新类型将是:
Try to create a type for ie2 instead of using an anonymous type, like:
Where the new type would be: