我有一个像这样定义的LinqDataSource:
<asp:LinqDataSource ID="LinqDataSource1" runat="server" OnSelecting="LinqDataSource_FileSelecting"></asp:LinqDataSource>在LinqDataSource_FileSelecting中,它返回/设置List<string>为e.Result,其中e是LinqDataSource的Selecting事件中的EventArgs(LinqDataSourceSelectEventArgs)。 页面加载时出现此错误:
“LinqDataSource'LinqDataSource1'的ContextTypeName属性必须指定数据上下文类型。”
根据这条消息并查看文档,我需要设置LinqDataSource的ContextTypeName和TableName属性。 ContextTypeName通常是类的名称,而TableName将是该类中可枚举属性的名称。
当数据源是一个List<string>我不确定我可以分配什么ContextTypeName或TableName。 我已经尝试了System.Collections.Generic.List<string>作为ContextTypeName,但没有奏效,我收到了“无法加载类型' System.Collections.Generic.List<string> ''”
我意识到,当数据源是在选择事件中生成的List<string>时,LinqDataSource可能不是合适的控件。 但是有没有可以为这种情况设置的ContextTypeName和TableName?
I have a LinqDataSource defined like this:
<asp:LinqDataSource ID="LinqDataSource1" runat="server" OnSelecting="LinqDataSource_FileSelecting"></asp:LinqDataSource>In LinqDataSource_FileSelecting, it returns/sets a List<string> to e.Result, where e is the EventArgs (LinqDataSourceSelectEventArgs) in the Selecting event of the LinqDataSource. I'm getting this error when the page loads:
"The ContextTypeName property of LinqDataSource 'LinqDataSource1' must specify a data context type."
Based on this message and looking at the docs, I need to set the ContextTypeName and TableName properties of the LinqDataSource. ContextTypeName would normally be the name of a class, and TableName would be the name of an enumerable property within that class.
When the data source is a List<string> I'm not sure what ContextTypeName or TableName I can assign. I've tried System.Collections.Generic.List<string> for the ContextTypeName, but that didn't work, I received "Could not load type 'System.Collections.Generic.List<string>'"
I realize the LinqDataSource may not be the appropriate control when the data source is a List<string> generated within the Selecting event. But is there a ContextTypeName and TableName I can set for this scenario?
最满意答案
找到答案。 事实证明,当使用Selecting事件并为e.Result分配一个List<string>时,你可以省略ContextTypeName和TableName。 但是,如果将null指定给e.Result,则会发生此错误,因为ASP.NET不知道数据的类型。 我选择事件的代码是为e.Result设置一个非空值,但是一个单独的问题导致null被设置为e.Result ...导致这个错误。
Found the answer. Turns out that you can omit ContextTypeName and TableName when using the Selecting event and assigning a List<string> to e.Result. However, if you assign null to e.Result, then this error will occur since ASP.NET doesn't know the type of data. My code on the Selecting event was designed to set a non-null value to e.Result, but a separate problem was leading to null being set to e.Result ... leading to this error.
更多推荐
ContextTypeName,LinqDataSource,List<string>,TableName,电脑培训,计算机培训,IT培训"
发布评论