我似乎无法弄清楚这一点,我对MVC模型并不陌生,但也许我的大脑只是疲惫不堪。Linq从列表中选择
视图模型
Public Class CategoriesViewModel
Public Property Categories As List(Of cihCategoryOrgDef)
Public Property Category As cihCategoryOrgDef
Public Property SelectedItem As String
Public Sub New(organizationId As Guid, codId As Guid)
Categories = lists.organizationClubCategories
Category = From x In Categories
Where x.codId = codId
Select x
End Sub
End Class
CategoriesController
Function Edit(codId As Guid) As ActionResult
Dim model As CategoriesViewModel = New CategoriesViewModel(ZenCommon.CurrentOrgId, codId)
Return View(model)
End Function
当我运行它,我得到一个 “无效强制转换异常” 的Category = From x....
线
Unable to cast object of type 'WhereSelectListIterator`2[Library.cihCategoryOrgDef,Library.cihCategoryOrgDef]' to type 'Library.cihCategoryOrgDef'.
我试图在我的View中使用一个Category
。所以我可以为该特定类别编辑一个页面。我是否全部错了?