Sharing models / and data between controller and view

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 years ago
This is all knew to me but I have spent a couple of weeks scratching, digging and using the google machine.

I have developed and Installed a new plugin that inserts new tables into the database
using all the rules in the existing videos.  I now have some nice new tables. I have also
injecting and consuming new services wrapping my data layer. All good so far! Got routing
working- yea!

I have created views within the plugin and that's fine!

Next I have created a custom theme  and got up a  site using view over - rides as in several examples.
Check!   Created new controllers and routes within the theme. Yea all good ! Yea!

Now, using "custom view engine"  as described - I can easily reach views in my theme from my
plugin. Using routing on buttons, I can reach my plugin controller from my theme, so I can
pass form data to my plugin.

I want to house my views in my theme cause that's  where my custom layouts live.
I want to use a plugin cause that is how I insert my additional tables.

1 .  I cannot figure out how to share viewmodels between the too areas.
2.  I cannot see any data service wrappers in the theme that I inject in the plugin. They seem to be local to the plugin ??
     and I can consume them in the plugin. I can see the build-in services in the theme views, but not not the ones created by the plugin.

3. Creating views in the plugin seems to work, but I cannot figure how to access my theme layouts.

4. I have noticed some verbiage about "templates" that I haven't studied, is this a way to share layouts?

Somewhere I am missing something fundamental. Any body who can set me straight will be my friend for ever.

__ clueless bebop
8 years ago
bebop45 wrote:
This is all knew to me but I have spent a couple of weeks scratching, digging and using the google machine.

I have developed and Installed a new plugin that inserts new tables into the database
using all the rules in the existing videos.  I now have some nice new tables. I have also
injecting and consuming new services wrapping my data layer. All good so far! Got routing
working- yea!

I have created views within the plugin and that's fine!

Next I have created a custom theme  and got up a  site using view over - rides as in several examples.
Check!   Created new controllers and routes within the theme. Yea all good ! Yea!

Now, using "custom view engine"  as described - I can easily reach views in my theme from my
plugin. Using routing on buttons, I can reach my plugin controller from my theme, so I can
pass form data to my plugin.

I want to house my views in my theme cause that's  where my custom layouts live.
I want to use a plugin cause that is how I insert my additional tables.

1 .  I cannot figure out how to share viewmodels between the too areas.
2.  I cannot see any data service wrappers in the theme that I inject in the plugin. They seem to be local to the plugin ??
     and I can consume them in the plugin. I can see the build-in services in the theme views, but not not the ones created by the plugin.

3. Creating views in the plugin seems to work, but I cannot figure how to access my theme layouts.

4. I have noticed some verbiage about "templates" that I haven't studied, is this a way to share layouts?

Somewhere I am missing something fundamental. Any body who can set me straight will be my friend for ever.

__ clueless bebop


1. If you create a folder in the active Theme Views folder same as your Plugin Controller Name. And keep view in that folder ..it must work. Use model ..that model you want to pass from controller
2. You can use the layout from plugin too by declaring @Layout="Path_layout"
8 years ago
Thank your post and quick response

I am afraid I did not explain myself well enough.


1. I have a new plugin which contains a new service, a new repository and a new controller.
    it works well enough within the plugin. I can add a view within the plugin.

2. I have a custom theme which overrides the default theme. It is also working fine.
     my theme contains several layouts. Within the theme are controllers and views.

First Problem  -  I do not want to duplicate my layouts and viewmodels in both the theme and plugin
                                 I want to share a single set of layouts/viewmodels  - if it is possible

    I don't think I can  reference the theme layouts  within the plugin views.
     ( At least I don't know how to this.)

    I can reach the theme views (which have able layouts / viewmodels ) from the
    plugin controller via  "custom view engine" from the plugin,  but I cannot
    see the services & stuff injected by the plugin in the theme view.

   Bottom line ->  Am I confused about what I am trying do, i.e. use plugin resources
  tith a theme, or do I just no know how to do it ??
8 years ago
bebop45 wrote:
Thank your post and quick response

I am afraid I did not explain myself well enough.


1. I have a new plugin which contains a new service, a new repository and a new controller.
    it works well enough within the plugin. I can add a view within the plugin.

2. I have a custom theme which overrides the default theme. It is also working fine.
     my theme contains several layouts. Within the theme are controllers and views.

First Problem  -  I do not want to duplicate my layouts and viewmodels in both the theme and plugin
                                 I want to share a single set of layouts/viewmodels  - if it is possible

    I don't think I can  reference the theme layouts  within the plugin views.
     ( At least I don't know how to this.)

    I can reach the theme views (which have able layouts / viewmodels ) from the
    plugin controller via  "custom view engine" from the plugin,  but I cannot
    see the services & stuff injected by the plugin in the theme view.

   Bottom line ->  Am I confused about what I am trying do, i.e. use plugin resources
  tith a theme, or do I just no know how to do it ??


Do you want to re use any Nop.Web model? Like ProductOverviewModel  and view like _PoductBox.cshtml . Then it is possible.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.