I have been going crazy with trying to load multiple partial views in an MVC 5 app I am writing in VB.Net. Don't ask Why VB, the client insisted on it.
The app has a form that pulls from six lookup tables and I need to make a form that the administrator can edit the values of these lookup tables from. The app has an edmx that the main form is built on and includes these six tables which worked very well for creating the main form, but I cannot find any way to create 6 partial views and load them into a single form.
I have tried How to Return partial view of another controller by controller? to load my partials and I have created separate classes and a View Model based on other posts.
Here is the code from the classes and view model I have tried with no luck.
My Classes.
Public Class CotListIems
Partial Public Class PlanList
Public Property Id As Integer
Public Property Superior As Decimal
Public Property Royal As Decimal
Public Property Maximo As Decimal
Public Property Manual As Boolean
Public Property ManSuperior As Nullable(Of Decimal)
Public Property ManRoyal As Nullable(Of Decimal)
Public Property ManMax As Nullable(Of Decimal)
End Class
Partial Public Class PlanRateList
Public Property Id As Short
Public Property Plan As String
Public Property Rate As Decimal
End Class
End Class
My View Model
Public Class AdminViewModel
Public Property PlanList As IEnumerable(Of PlanList)
Public Property PlanRateList As IEnumerable(Of PlanRateList)
End Class
My Controller
Function Admin(ByVal id As Integer?) As ActionResult
Dim viewModel = New AdminViewModel()
viewModel.PlanList = db.Plans.Include(Function(i) i.Id).Include(Function(c) c.Superior).Include(Function(c) c.Royal).Include(Function(c) c.Maximo).Include(Function(c) c.Manual).Include(Function(c) c.ManSuperior).Include(Function(c) c.ManRoyal).Include(Function(c) c.ManMax)
viewModel.PlanRateList = db.PlanRates.Include(Function(i) i.Id).Include(Function(c) c.Plan).Include(Function(c) c.Rate)
Return View(viewModel)
End Function
The Controller I added here is one that I tried to create, but I have also tried to scaffold one.
When I try to scaffold a new controller based on my view model I get Entity Type 'AdminViewModel' has no key defined. Define a key for this EntityType. I cannot find any information on how to define a key for this, only for C#, all VB documentation seems to only work for anonymous types and looks to be static hard coded key values.
I'm really stuck here as it seems there are many ways and all I want to do is list the contents of six lookup tables on the same page with Edit links for each section to load them in another view. Thanks, I know this is probably basic stuff, but it's confusing and very frustrating at the moment.