Plugin: admin routes - Page Not Found

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 10 años
Nesse wrote:
It's still not working. I've debugged my plugin, and it never hits RegisterRoutes. Not on install, reloading all plugins, ... So strange. It should at least have one hit. My RouteProvicer.cs file is set to compile.

Can you post the full content of your RouteProvider.cs?

I've made more than a dozen plugins, but never came across this problem.


using System.Web.Mvc;
using System.Web.Routing;
using Nop.Web.Framework.Mvc.Routes;

namespace Nop.Plugin.Misc.CustomerService
{
    public partial class RouteProvider : IRouteProvider
    {
        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute("Nop.Plugin.Misc.CustomerService.Test",
                 "Plugins/CustomerService/Test",
                 new { controller = "Test", action = "Test" },
                 new[] { "Nop.Plugin.Misc.CustomerService.Controllers" }
            );

          
        }
        public int Priority
        {
            get
            {
                return 0;
            }
        }
    }
}


Controller:


using System.Web.Mvc;
using Nop.Plugin.Misc.CustomerService.Models;

namespace Nop.Plugin.Misc.CustomerService.Controllers
{
    public class TestController : Controller
    {

        public ActionResult Test()
        {
            var model = new PageListModel();
          
            return View("Nop.Plugin.Misc.CustomerService.Views._CustomerServiceAdmin.List", model);

        }

    }
}


Looks ok to me, unless I am missing anything. Could it be that your plugin is not installed?

Or if you don't mind, you can PM me your plugin code. I can run the debug on my machine and see what's the problem.

:)
Hace 7 años
I have same problem. Can you help me fix that
Hace 7 años
Hi Huykon,

Could you please add some more information, with your scenario.
Hace 7 años
TrackingController file:

using Nop.Core.Data;
using Nop.Plugin.Other.MyPlugin.Domain;
using Nop.Web.Framework.Controllers;
using System.Web.Mvc;

namespace Nop.Plugin.Other.MyPlugin.Controllers
{
    [AdminAuthorize]
    public class TrackingController : BasePluginController
    {
        private IRepository<TrackingRecord> _iRepository;

        public TrackingController(IRepository<TrackingRecord> iRepository)
        {
            _iRepository = iRepository;
        }
        
        [HttpGet]
        public ActionResult Manage()
        {
            return View("~/Plugins/Other.MyPlugin/Views/Manage.cshtml");
        }
    }
}


RouteProvider file:

using Nop.Plugin.Other.MyPlugin.Infrastructure;
using Nop.Web.Framework.Mvc.Routes;
using System.Web.Mvc;
using System.Web.Routing;

namespace Nop.Plugin.Other.MyPlugin
{
    public class RouteProvider : IRouteProvider
    {
        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute("Plugins.Other.MyPlugin.Manage",
                "Plugins/Other/MyPlugin/Manage",
                new { controller = "Tracking", action = "Manage" },
                new[] { "Nop.Plugin.Other.MyPlugin.Controllers" }
           );
           //ViewEngines.Engines.Insert(0,new CustomView());
        }

        public int Priority
        {
            get
            {
                return 0;
            }
        }
    }
}


And this is tree directory plugin:


Please help me !!
Hace 6 años
This is rather later but, in case anyone else wants to solve this issue...

use routes.Insert(...)


routes.Insert(0, new Route("admin/myplugin/settings",
   new RouteValueDictionary {{"controller", "MyPlugin"}, {"action", "Settings"}},
   new MvcRouteHandler()));


Just replace MyPlugin with your controller name (minus Controller) and Settings with your action.
Hace 6 años
You could also use ThemeableRazorViewEngine to make your own CustomViewEngine like so:

using Nop.Web.Framework.Themes;

namespace Nop.Plugin.Widgets.MyPlugin.Infrastructure
{
    public class CustomViewEngine : ThemeableRazorViewEngine
    {
        public CustomViewEngine()
        {
            ViewLocationFormats = new[] { "~/Plugins/Widgets.MyPlugin/Views/{0}.cshtml" };
            PartialViewLocationFormats = new[] { "~/Plugins/Widgets.MyPlugin/Views/{0}.cshtml" };
        }
    }
}


and implement it in your RouteProvider.cs file:

using System.Web.Mvc;
using System.Web.Routing;
using Nop.Plugin.Widgets.MyPlugin.Infrastructure;
using Nop.Web.Framework.Mvc.Routes;

namespace Nop.Plugin.Widgets.MyPlugin
{
    public class RouteProvider : IRouteProvider
    {
        public int Priority => 0;

        public void RegisterRoutes(RouteCollection routes)
        {
            ViewEngines.Engines.Insert(0, new CustomViewEngine());
        }
    }
}


Works for me every time!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.