Vb.net函数返回模型中的列表

时间:2015-11-05 01:54:18

标签: asp.net asp.net-mvc vb.net webforms

我正在创建一个函数,它必须返回学生列表,以便我可以在我的html页面上显示它

模型

Public Class Student
    Public Property Name() As String
End Class

告诉我如何写当前函数返回

Public Function FillList() As IList(Of Student)
    Dim Obj as IList(Of Student) = new IList(Of Student)
    Dim Obj_Student As Student = new Student

    Obj_Student.Name = "Zeor"
    Obj.Add(Obj_Student)

    Obj_Student.Name = "One"
    Obj.Add(Obj_Student)

    return Obj_Student
End Function

但我收到错误

<asp:Repeater id="cdcatalog" runat="server" SelectMethod ="FillList" ItemType="WebApplication16.Student">
   <ItemTemplate>
       <td><%# Item.Name %></td>
   </ItemTemplate>
</asp:Repeater>
    <p>Your app description page.</p>
    <p>Use this area to provide additional information.</p>
</asp:Content>

我们可以将模型发送到Aspx Web表单

和其他问题是如何发送模型,从Aspx到Html,我可以使用html中的每一个,就像我们在MVC中使用我在Web窗体中的新... ...

2 个答案:

答案 0 :(得分:0)

FillList无法执行此操作:

Dim Obj as IList( of Student) = NEW IList( of Student)

必须在New构造函数中使用List:

Dim Obj as IList( of Student) = NEW List( of Student)

答案 1 :(得分:0)

 Dim obj As List(Of Student)  = New List(Of Student)

  Dim Su As New Student

        Su.Name ="aaa" 
        obj.Add(Su)
          Su.Name ="aaaaa"
obj.Add(Su)