DropDownListFor使用Class的List

时间:2014-10-08 17:22:37

标签: vb.net html.dropdownlistfor

我似乎无法让我的HTML.DropDownListFor()与我的结构一起正常工作。

CategoriesEditViewModel

Public Class CategoriesEditViewModel
    Public Property Categories As List(Of cihCategoryOrgDef)
    Public Property Category As cihCategoryOrgDef
    Public Property lists As cihLists = New cihLists()

    Public Property SelectedItem As String

    Public Sub New(catId as Guid)
     SelectedItem = codId.ToString
     lists.loadClubWaivers(ZenCommon.CurrentOrgId)
    End Sub
End Class

cihLists

   Private orgWaiverList As List(of cihWaiver)

   Public Sub loadClubWaivers(orgId as Guid)
    'Go to database and populate orgWaiverList
   End Sub

 Public ReadOnly Property organizationClubWaivers() As List(Of cihWaiver)
        Get
            Return orgWaiverList
        End Get
    End Property

cihWaiver

Public Class cihWaiver
    Public waiverId As Guid = Guid.Empty
    Public waiverName As String = ""
    Public waiverText As String = ""
End Class

修改视图页

@Html.DropDownListFor(Function(m) m.SelectedItem, New SelectList(Model.lists.organizationClubWaivers, "waiverId", "waiverText", Model.lists.organizationClubWaivers))

我得到的错误是'Library.cihWaiver' does not contain a property with the name 'waiverId'.

但是cihWaiver类显然有一个“waiverId”项目。我有一段时间没有完成MVC的工作,所以也许我对这一切都做错了。

1 个答案:

答案 0 :(得分:0)

答案就像将 cihWaiver 类更改为此一样简单:

Public Class cihWaiver
    Public Property waiverId As Guid = Guid.Empty
    Public Property waiverName As String = ""
    Public waiverText As String = ""
End Class

有人向我解释为什么关键字Property如此重要?