【问题标题】:Vb.net Function Return list from the ModelVb.net 函数从模型返回列表
【发布时间】:2016-02-05 17:52:14
【问题描述】:

我正在创建一个函数,它必须返回学生列表,以便我可以在我的 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,我可以使用 For each in that with html,就像我们在 MVC 中所做的那样,使用我是 Web 表单中的新手...

【问题讨论】:

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


    【解决方案1】:
     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)
    

    【讨论】:

      【解决方案2】:

      FillList 不能这样做:

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

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

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

      【讨论】:

        猜你喜欢
        • 2019-05-20
        • 1970-01-01
        • 2023-03-14
        • 1970-01-01
        • 2013-03-21
        • 1970-01-01
        • 2018-03-28
        • 1970-01-01
        相关资源
        最近更新 更多