VB.NET MVC无法访问Viewmodel中的模型?
我想在视图中显示联接表的结果集,我通过创建一个包含两个模型(开发人员和报表)的viewmodel来实现这一点,控制器中的查询将数据分配给viewmodel。然而,似乎我无法从控制器访问模型。我想知道是否有可能这样做?如果是我做错了什么 报告模型:VB.NET MVC无法访问Viewmodel中的模型?,vb.net,asp.net-mvc-5,Vb.net,Asp.net Mvc 5,我想在视图中显示联接表的结果集,我通过创建一个包含两个模型(开发人员和报表)的viewmodel来实现这一点,控制器中的查询将数据分配给viewmodel。然而,似乎我无法从控制器访问模型。我想知道是否有可能这样做?如果是我做错了什么 报告模型: Imports System.Data.Entity Public Class Report Public Property Id As Integer Public Property Name As String Publi
Imports System.Data.Entity
Public Class Report
Public Property Id As Integer
Public Property Name As String
Public Property Dev_id As Integer
End Class
开发人员模型:
Imports System.Data.Entity
Public Class Developer
Public Property Id As Integer
Public Property FirstName As String
Public Property LastName As String
Public Property DT_created As DateTime
Public Property DT_last_modified As DateTime
End Class
ViewmodelReport:
Imports System.Data.Entity
Public Class ViewModelReport
Public Property reports As New Report
Public Property developers As New Developer
End Class
控制器:
Namespace Controllers
Public Class TrackerController
Inherits Controller
Dim db As New Analytic
' GET: Tracker
Function Index() As ActionResult
Dim vm As ViewModelReport = New ViewModelReport()
Dim rep = From r In db.Reports
Join d In db.Developers
On r.Dev_id Equals d.Id
Join ac In db.Audit_changes
On ac.Report_Id Equals r.Id
Select New ViewModelReport With {
.reports. ***<----does not show reports properties***
}
Return View(vm)
End Function
我不希望它在那里显示报告的属性。它在with块中需要一个报表变量。你应该能做到 .reports=带有{….等的新报告
将值分配给报表类。ViewModelReport在哪个命名空间中?该命名空间是否已在控制器中导入引用?@David,我没有为ViewModelReport定义命名空间,但我确信它已被引用,因为我能够在控制器中创建ViewModelReport对象。