1

我有一个关于 @Html.DropDownListFor 的问题

我有 2 节课:

Public Class A01WorkRecord
Public Property counter As Int32
Public Property MembetNumber As Int16
Public Property Memo As String
Public Property WorkDate As Date
End Class

Public Class B01Member
Public Property counter As Int32
Public Property Number As Int16
Public Property Name As Date
End Class

VIEW 用于创建工作记录,所以我希望视图可以选择成员名称并编写工作备忘录

所以在控制器中

Function Index() As ActionResult
    Dim q = From p In db.B01s
            Select p.Number, p.Name

    Dim ListItem As List(Of SelectListItem) = New List(Of SelectListItem)
    For Each l In q
        ListItem.Add(New SelectListItem With {.Text = l.Name, .Value = l.Number})
    Next
    ViewData("List") = New SelectList(ListItem, "Value", "Text", "")

    Return View()
End Function

并在视图中

@Html.DropDownListFor(Function(model) model.MembetNumber ,ViewData("Item"))

我想选择名字,但它不起作用......

错误信息:

没有类型是 'IEnumerable' 和索引 'Number' ViewData 项

我不知道怎么了,请帮助我。

4

1 回答 1

2

从提供的示例看来,您可能正在ViewData("Item")混淆ViewData("List")

所以试试这个

@Html.DropDownListFor(Function(model) model.MembetNumber, ViewData("List"))
于 2013-01-04T06:29:20.453 回答