[英]VB.NET MVC Can't Access Models in Viewmodel?
I want to display the result set of join tables in the view, I approach this by creating a viewmodel that contains two models, developers and reports, and a query in the controller assigns the data to the viewmodel. 我想在视图中显示联接表的结果集,我通过创建一个包含两个模型(开发者和报告)的viewmodel来实现这一点,并且控制器中的查询将数据分配给该viewmodel。 However it seems like I can't access the models from controller.
但是似乎我无法从控制器访问模型。 I wonder if it's possible to do so?
我想知道是否可以这样做? if it is what I did wrong?
如果这是我做错了?
Report model: 报告模型:
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
Developer model: 开发者模型:
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: ViewmodelReport:
Imports System.Data.Entity
Public Class ViewModelReport
Public Property reports As New Report
Public Property developers As New Developer
End Class
Controller: 控制器:
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
I would not expect it to show the properties of the report in there. 我不希望它在那里显示报告的属性。 It is expecting a report variable in the with block.
期望with块中有一个报告变量。 You should be able to do
你应该能够做
.reports = new Report With {.....etc .reports =带有{..... etc的新报告
to assign the values to the report class. 将值分配给报告类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.