devdev
devdev

Reputation: 73

Issue with partial view and viewmodel in separate assembly

I am developing an MVC solution and I want to have a plugin option for some partial views I am creating. I have separate assembly for each plugin that contains the PartialView as an embedded resource and the viewmodel class that it references. I use a virtualfile provider to find the required PartialView and this works great...until I try to use the ViewModel for the partial.

To render the partial view, I have two properties in the Model that get set at runtime depending on the option chosen...so I use the following:

    Html.RenderPartial(Model.PartialViewName, Model.PartialViewModel) 

where Model.PartialViewModel is an interface that all the view models in the separate assemblies implement.

I get the following error when the partial view is rendering: error CS1061 'object' does not contain a definition for '{PropertyName}' and no extension method '{PropertyName}' accepting a first argument of type 'object' could be found..." This error occurs for whatever property on the partial viewmodel I'm trying to access.

However, when in debug mode, I can see the viewmodel that has been passed to the partial view and it is correct and all the properties are there and populated. I have even went so far as to remove the plugin-ness and just reference the named classes and types (instead of interfaces) and I still get this error.

Any ideas? Anyone been able to put a partial view and its viewmodel in a separate assembly and get it to work? Thank you.

Upvotes: 1

Views: 392

Answers (0)

Related Questions