0

I have a nopCommerce plugin which has a custom view engine as following:

CustomViewEngine : ThemeableRazorViewEngine

The plugin has a view file called CategoryNavigation.cshtml which also exists at Views\Catalog\CategoryNavigation.cshtml

Now if I delete the files the error reported by the view engines are as following: enter image description here

As you can see the first searched location is the plugin folder.

So if the file exists in the plugin folder but not in the Views\Catalog\ folder then it is displayed from the plugin folder without any error. But if the file exists both in the plugin folder and in Views\Catalog\ then the view from the Views\Catalog\ is rendered. But the Views\Catalog\ is way down in the search locations (see the image above). Any idea what might be causing the issue?

nopCommerce 3.70

Rahatur
  • 3,147
  • 3
  • 33
  • 49
  • From where you have deleted the file? from default view's? – Divyang Desai Aug 19 '16 at 02:49
  • And what you actually want? Want to display view from your plugin ? – Divyang Desai Aug 19 '16 at 02:53
  • @Div, I deleted/renamed the file to see the search locations of the view engine. Then I restored the file. I need the view from the plugin to render not the default view. – Rahatur Aug 19 '16 at 08:21
  • you have to give a same name of folder like `~/Plugin/Feed.Instagram/Views/Catalog/CategoryNavigation.cshtml` – Divyang Desai Aug 19 '16 at 08:40
  • Make a folder with the name catalog and paste your view page into it. – Divyang Desai Aug 19 '16 at 08:41
  • That will not work as its a plugin. Also as you can see the view engine is looking into the plugin folder first. But when the file exists in both location it is picking the file from the second location. – Rahatur Aug 19 '16 at 13:44

1 Answers1

1

I need the view from the plugin to render not the default view

If you want to display view page form your plugin, you should use plugin view engine, that you've already done. But make sure you also define ViewLocationFormats like following.

 public class CustomViewEngine :ThemeableRazorViewEngine 
    {         
        public CustomViewEngine ()
        {    
            ViewLocationFormats =
                new[]
                {                               
                     "~/Plugins/Feed.Instagram/Views/Catalog/{0}.cshtml"
                };
        }  
    }

Here create a folder(catalog) in your view folder and paste​categoryNavigation.csh‌​tml into it.

It will display view page from your plugin instead of default.

Hope this will help to you!

For more information refer this: Ways to Display Views in Your nopCommerce Plugins

Divyang Desai
  • 7,483
  • 13
  • 50
  • 76
  • This bit is already done (mentioned in the description) - "if the file exists in the plugin folder but not in the Views\Catalog\ folder then it is displayed from the plugin folder without any error. But if the file exists both in the plugin folder and in Views\Catalog\ then the view from the Views\Catalog\ is rendered." – Rahatur Aug 19 '16 at 14:01
  • Which version of nopCommerce you are using? – Divyang Desai Aug 19 '16 at 14:09
  • May be something that you are missing or need to change, also you haven't mentioned that you're using theme. – Divyang Desai Aug 19 '16 at 14:47
  • Otherwise, plugin view engine works fine when view file are available at both the places. It's override your view page – Divyang Desai Aug 19 '16 at 14:50
  • The is a theme but the CategoryNavigation is not in that theme. It is being rendered from the default view\Catalog folder. So the theme is not effecting anything here. As you can see it is looking for the view file in Plugin then Theme and then the default view folder. – Rahatur Aug 19 '16 at 15:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/121366/discussion-between-div-and-rahat). – Divyang Desai Aug 19 '16 at 16:54
  • No it has not been resolved. We can discuss on Sunday 5PM IST? – Rahatur Aug 27 '16 at 16:37