How to deal with models when I want to override the build-in view

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 anno tempo fa
Hi all,

I've overridden a view in my plugin using IViewLocationExpander, it all works just fine. The question I have is... if a view I've overridden has a quite complicated Model bound to it, it seems that I have to copy over all models and referenced/related models into my plugin, repeating (copying) the content, because there is no way to reference the build in models in my plugin.
Is there something I am missing conceptually and there is a better way of doing this?  

the view I've overridden: Catalog => _ProductsInGridOrLines.cshtml, that means I need to copy: almost all Product and filter related models and I am not even sure that is going to work...
1 anno tempo fa
You could try and reference the Model and use the namespace
i.e. Nop.Web.Models.Catalog.CatalogProductsModel
1 anno tempo fa
You don't have to copy over all models, you just need to add the reference so that it finds the correct namespace and belonging models.
For example: If you trying to override the _ProductsInGridOrLines.cshtml, You need to add Nop.Web reference to your plugin first, then to use a particular model from Nop.Web. For your view, You need to have the CatalogProductsModel model in your overriden view file, for that you have to use Nop.Web.Models.Catalog namespace there. So add the @using Nop.Web.Models.Catalog and then @model CatalogProductsModel and it should work. You can organize the @using statements in your _ViewImports.cshtml file too.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.