0

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.

Community
  • 1
  • 1
Ed Kratz
  • 73
  • 1
  • 1
  • 5
  • 1
    And, what's wrong with VB.NET? It's pretty much equivalent in functionality to C#, except where it has _more_ features than C#. And "lack of documentation"? Have you looked at http://asp.net? – John Saunders May 02 '15 at 22:55
  • John, there is nothing wrong with VB.Net except that searching for solutions to problems and trying to learn it can be pretty frustrating. I used vb from version 4 through .Net framework 2 almost exclusively but it was mostly desktop apps and front ends for SQL Server. And yes, I've check asp.net, I've been looking everywhere for a solution, but it seems that most people use code first and I'm just trying to get up to speed on how partial views work, it seems like it should be pretty straightforward but I'm really struggling to find a single example on the best approach. – Ed Kratz May 02 '15 at 23:05
  • 1
    Then stop looking for examples! Go learn the technology. Then you can _write_ the example! – John Saunders May 02 '15 at 23:10
  • [This article explains how to return multiple views in one action result](https://www.simple-talk.com/dotnet/asp.net/revisiting-partial-view-rendering-in-asp.net-mvc/) This might help. – Jason Evans May 03 '15 at 10:38

0 Answers0