• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VB .Net MVC question

douglasb

Diamond Member
We are working on an MVC project in VB .Net at my job. My previous MVC background is entirely in C#.

In this project, we have:
Code:
MainModel - has a "SubModel1" property, "SubModel2", etc.
SubModel1 - a model that we want to show in a partial view that is strongly typed to it
SubModel2 - a model that we want to show in a partial view that is strongly typed to it 
SubModel3 - a model that we want to show in a partial view that is strongly typed to it
MainView - strongly typed to MainModel.  It contains a PartialView1, PartialView2, etc.
PartialView1 - strongly typed to SubModel1
PartialView2 - strongly typed to SubModel2
PartialView3 - strongly typed to SubModel3

In the MainView, somewhere we have:
Code:
@Html.Partial("foo", Model.SubModel1)

Now, when the VB Parser gets to this last part, it crashes. For some reason, it gives an error that the wrong type of model was passed in. The compiler correctly infers that Model.SubModel1 is of SubModel1 type, but the Parser does not.

These "SubModel" properties are all Public Overridable Property of their respective types. I understand that this is the equivalent to "public virtual myType" in C#.

This code works fine in C#, and I have done it many times before. But for some reason, VB thinks there is an error. Any ideas? And no, "just use C#" won't work because the other developers here are highly resistant to using any language other than VB.
 
It looks like this error only occurs when the SubModel1 is null ("Nothing" in VB). I suppose that we can either set it to a New SubModel1 in the MainModel constructor, or do the same thing in the Controller.
 
Back
Top