ViewEngine's location search order is ok but renders the view from wrong folder

302 views Asked by At

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

1

There are 1 answers

7
Divyang Desai On

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