Override Default Category action method of Catalog Controller using Plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
sorry for the previous reply that happens by mistake.yes I need solution for controller override . I want to override the admin blog controller.
7 years ago
harshitporwal wrote:
sorry for the previous reply that happens by mistake.yes I need solution for controller override . I want to override the admin blog controller.


Actually I did not override controller I override a generic route.
7 years ago
sina.islam wrote:
sorry for the previous reply that happens by mistake.yes I need solution for controller override . I want to override the admin blog controller.

Actually I did not override controller I override a generic route.

Why don't you post the code here on the forum?
7 years ago
My plugin 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:



As you can see the first searched location is the plugin folder. If the file exists in the plugin folder it is displayed without any error. But if the file exists both in the plugin folder and in Views\Catalog  then the view from Views\Catalog  is rendered instead of the plugin folder. Tho that is way down in the search location.
Any idea what might be causing the issue?

Nop 3.70
7 years ago
rahat wrote:
My plugin 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:



As you can see the first searched location is the plugin folder. If the file exists in the plugin folder it is displayed without any error. But if the file exists both in the plugin folder and in Views\Catalog  then the view from Views\Catalog  is rendered instead of the plugin folder. Tho that is way down in the search location.
Any idea what might be causing the issue?

Nop 3.70



As the CategoryNavigation.cshtml view exist in two locations so the viewengine confuse which one it will show. The solution is write

return PartialView("~/Plugins/YourPlugin/Views/YourView/CategoryNavigation.cshtml", model);

at controller. Where from the view appear. I mean at

public ActionResult CategoryNavigation(int currentCategoryId, int currentProductId)
{
...................
}
7 years ago
sina.islam wrote:


As the CategoryNavigation.cshtml view exist in two locations so the viewengine confuse which one it will show. The solution is write

return PartialView("~/Plugins/YourPlugin/Views/YourView/CategoryNavigation.cshtml", model);

at controller. Where from the view appear. I mean at

public ActionResult CategoryNavigation(int currentCategoryId, int currentProductId)
{
...................
}

I do not think the view engine is confused! A file can exist in multiple locations and the first searched-found location is returned. That is how the MVC works.

I am not having any error in the application. I just need the view rendered from the plugin. I am trying to override the left category section from a plugin. That is why I do not want to modify the Catalog controller either.
7 years ago
rahat wrote:


As the CategoryNavigation.cshtml view exist in two locations so the viewengine confuse which one it will show. The solution is write

return PartialView("~/Plugins/YourPlugin/Views/YourView/CategoryNavigation.cshtml", model);

at controller. Where from the view appear. I mean at

public ActionResult CategoryNavigation(int currentCategoryId, int currentProductId)
{
...................
}
I do not think the view engine is confused! A file can exist in multiple locations and the first searched-found location is returned. That is how the MVC works.

I am not having any error in the application. I just need the view rendered from the plugin. I am trying to override the left category section from a plugin. That is why I do not want to modify the Catalog controller either.




Ok let me understand your requirement first. If you want to show "CategoryNavigation.cshtm" view from your plugin then at _ColumnsTwo.cshtml you may write

@Html.Action("YourCustomCategoryNavigation", "YourPluginController", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId })

The "YourCustomCategoryNavigation" method will have the same functionality as the default one but it will return

return PartialView("~/Plugins/YourPlugin/Views/YourView/CategoryNavigation.cshtml", model);

If you do not want to change _ColumnsTwo.cshtml  then you need to handle it by widget.
7 years ago
sina.islam wrote:




Ok let me understand your requirement first. If you want to show "CategoryNavigation.cshtm" view from your plugin then at _ColumnsTwo.cshtml you may write

@Html.Action("YourCustomCategoryNavigation", "YourPluginController", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId })

The "YourCustomCategoryNavigation" method will have the same functionality as the default one but it will return

return PartialView("~/Plugins/YourPlugin/Views/YourView/CategoryNavigation.cshtml", model);



Hi Dear sina.islam,

What will be happened when the plugin will unavailable or uninstall?
7 years ago
sohel wrote:




Ok let me understand your requirement first. If you want to show "CategoryNavigation.cshtm" view from your plugin then at _ColumnsTwo.cshtml you may write

@Html.Action("YourCustomCategoryNavigation", "YourPluginController", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId })

The "YourCustomCategoryNavigation" method will have the same functionality as the default one but it will return

return PartialView("~/Plugins/YourPlugin/Views/YourView/CategoryNavigation.cshtml", model);



Hi Dear sina.islam,

What will be happened when the plugin will unavailable or uninstall?


if anybody write

@Html.Action("YourCustomCategoryNavigation", "YourPluginController", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId })

and the plugin is not exist then the above method will not work.
7 years ago
sina.islam wrote:




Ok let me understand your requirement first. If you want to show "CategoryNavigation.cshtm" view from your plugin then at _ColumnsTwo.cshtml you may write

@Html.Action("YourCustomCategoryNavigation", "YourPluginController", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId })

The "YourCustomCategoryNavigation" method will have the same functionality as the default one but it will return

return PartialView("~/Plugins/YourPlugin/Views/YourView/CategoryNavigation.cshtml", model);



Hi Dear sina.islam,

What will be happened when the plugin will unavailable or uninstall?

if anybody write

@Html.Action("YourCustomCategoryNavigation", "YourPluginController", new { currentCategoryId = currentCategoryId, currentProductId = currentProductId })

and the plugin is not exist then the above method will not work.


And also error occurred!!!!!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.