Issue with plugin route - Page not found

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
I'm trying to create a custom route in my plugin. When I navigate to the route url I configured I get the classic nop page not found. Though I researched quite a bit can't find what's wrong in here:
-The Route Provider
 
       public int Priority => 0;

        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapLocalizedRoute("Nop.Plugin.Misc.CustomEnvironments.PrintTest",
                "CustomEnvironments/Campaigns",
                new { Controller = "CustomEnvironmentsController", Action = "PrintTest" },
                new[] { "Nop.Plugin.Misc.CustomEnvironments.Controllers" }
            );

-The Controller & Action
    public class CustomEnvironmentsController : BasePluginController
    {
        private IRepository<SalesPrice> _salesPriceRepo;

        public CustomEnvironmentsController(IRepository<SalesPrice> salesPriceRepo)
        {
            _salesPriceRepo = salesPriceRepo;
        }

        public ActionResult PrintTest()
        {
            return View("~Plugins/Misc.CustomEnvironments/Views/Test.cshtml");
        }
}
4 years ago
look at here https://www.nopcommerce.com/boards/topic/75648/cannot-get-a-new-page-to-work-in-nop-40#254075

may be this will help you.
4 years ago
Line  
new { Controller = "CustomEnvironmentsController", Action = "PrintTest" },

should be

  new { Controller = "CustomEnvironments", Action = "PrintTest" },


You just assign controller name with controller word.
So change this

 public int Priority => 0;

        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapLocalizedRoute("Nop.Plugin.Misc.CustomEnvironments.PrintTest",
                "CustomEnvironments/Campaigns",
                new { Controller = "CustomEnvironmentsController", Action = "PrintTest" },
                new[] { "Nop.Plugin.Misc.CustomEnvironments.Controllers" }
            );

to

 public int Priority => 0;

        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapLocalizedRoute("Nop.Plugin.Misc.CustomEnvironments.PrintTest",
                "CustomEnvironments/Campaigns",
                new { Controller = "CustomEnvironments", Action = "PrintTest" },
                new[] { "Nop.Plugin.Misc.CustomEnvironments.Controllers" }
            );
4 years ago
Thanks. Don't know how I missed that
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.