c# - 使用 vb 返回 IEnumerable 时,Asp.net 4.5 模型绑定(bind)中断?

标签 c# asp.net vb.net asp.net-4.5

我有一个 GridView 如下:

<asp:GridView ID="gv" runat="server" SelectMethod="gv_GetData" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="true">
</asp:GridView>

我在 c# 中有以下有效的代码:

public IList<string> gv_GetData(int maximumRows, int startRowIndex, out int totalRowCount, string sortByExpression)
{
    List<string> l = GetTestData();
    totalRowCount = l.Count;
    return l;
}

private List<string> GetTestData()
{
    List<string> l = new List<string>();
    l.Add("a");
    l.Add("b");
    l.Add("c");
    return l;
}

现在,在 VB 中我有:

Public Function gv_GetData(maximumRows As Integer, startRowIndex As Integer, ByRef totalRowCount As Integer, sortByExpression As String) As IList(Of String)
    Dim l As List(Of String) = GetTestData()
    totalRowCount = l.Count
    Return l
End Function

Private Function GetTestData() As List(Of String)
    Dim l As New List(Of String)()
    l.Add("a")
    l.Add("b")
    l.Add("c")
    Return l
End Function

VB 版本总是产生以下错误:

When the DataBoundControl has paging enabled, either the SelectMethod should return an IQueryable or should have all these mandatory parameters : int startRowIndex, int maximumRows, out int totalRowCount

这可能是框架错误吗?还是我漏掉了一些过于明显的东西?


下面由 nemesv 回答。新方法是:

Public Function gv_GetData(maximumRows As Integer, startRowIndex As Integer, <System.Runtime.InteropServices.Out()> ByRef totalRowCount As Integer, sortByExpression As String) As IList(Of String)
    Dim l As List(Of String) = GetTestData()
    totalRowCount = l.Count
    Return l
End Function

最佳答案

您需要用 OutAttribute 标记 totalRowCount

<Out()> ByRef totalRowCount As Integer

这在语义上等同于 c# out 关键字。

关于c# - 使用 vb 返回 IEnumerable 时,Asp.net 4.5 模型绑定(bind)中断?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12059456/

相关文章:

c# - 从 PDF 的特定页面中提取图像

c# - SignalR - 从上下文调用静态类型的集线器

c# - 如何测量应用程序加载所有使用的程序集所花费的时间?

c# - 什么是 ProfileService/ProfileService 何时执行?

jquery - 我如何使用 jQuery 隐藏或显示基于 asp.net 角色的表行?

.net - DataGridView 过滤器忽略单元格、单词上的变音符号(重音)

c# - NReco 错误 : "The specified executable is not a valid application for this OS platform"

vb.net - TextFieldParser 类

c# - 安装后无法访问 SQLite 数据库

c# - 无法备份 mysql 数据库,错误为 "The given path' s 格式不受支持。”