【问题标题】:ItemType for System.Linq.IGrouping when using Strongly-Typed Data Controls gives "Could not load type" error使用强类型数据控件时 System.Linq.IGrouping 的 ItemType 给出“无法加载类型”错误
【发布时间】:2014-08-19 12:16:41
【问题描述】:

我正在尝试使用转发器控件显示 Linq 分组结果。我的 ASPx 代码如下:

<asp:Repeater runat="server" ItemType="System.Linq.IGrouping`2[System.Int32, myProject.Student]">
    <ItemTemplate>
        Age: <%# Item.Key %> / Count <%# Item.Count() %>
        //Maybe another repeater for each record in the group
    </ItemTemplate>
</asp:Repeater>

Select 方法是:

public System.Linq.IGrouping<Int32, myProject.Student> Repeater_StudentByAge_GetData()
    {
        return new context().Student.GroupBy(x=>x.Age);
    }

Visual Studio IntelliSense 与我的 ItemType 声明配合良好,但在运行时收到以下错误:

Could not load type'System.Linq.IGrouping2[System.Int32, myProject.Student]'.`

我可以知道什么是正确的方法吗?

【问题讨论】:

    标签: asp.net linq webforms repeater


    【解决方案1】:

    省去你自己的麻烦,并在转发器中为该项目引入一个类。它会更容易阅读和维护。

    【讨论】:

      猜你喜欢
      • 2011-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-10
      • 2020-09-05
      • 1970-01-01
      相关资源
      最近更新 更多