Plugin Routing Issue

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Hi,

I am unsure whether anyone is able to help me.

I am trying to write a plugin for nopcommerce, I can load a partial view however I am unable to get to the controller using the route I have specified.

The assembly is called Nop.Plugin.Search.Bikes, this is the route I have specified:
 routes.MapRoute("Plugin.Search.Bikes.Index","Plugins/BikeSearch",new { controller = "BikeSearch", action = "Index" }, new[] {"Nop.Plugin.Search.Bikes.Controllers"});
            routes.MapRoute("Plugin.Search.Bikes.GetYears","Plugins/BikeSearch/GetYears", new { controller = "BikeSearch", action = "YearList" }, new[] {"Nop.Plugin.Search.Bikes.Controllers"});


I have used Glimpse and am able to see that the route is installed and that it appears to have the correct datatoken values.

I can also see that the Install is working as the data table relating to the plugin is created.

Driving me nuts that the controller doensn't appear to be usable (By going /Plugins/BikeSearch returns 302 page not found error) and it's probably down to something stupid that i have forgotten.

Any Ideas?

Regards,

DJPERROTT
11 years ago
302 shouldn't be 'page not found' btw. Are you doing any redirection in your Action? :)
11 years ago
did you set your projects output directory correctly? (something like: ..\..\Presentation\Nop.Web\Plugins\Widgets.BikeSearch)
11 years ago
The controller is supposed to return the Index view if the request is not an AJAX request.

When I step through the partial view's javascript it does the same and doesn't get any return.

I have set the output folder for the project to ..\..\Presentation\Nop.Web\Plugins\Search.Bikes\

Regards,

djperrott
11 years ago
If it's any help, below is the code for the controller:


public ActionResult Index()
        {

            return PartialView("Nop.Plugin.Search.Bikes.Views.BikeSearch.Index"); ;
        }

// This collects the distinct years in the database, output is cached
[OutputCache(Duration = 60, VaryByParam = "None")]
public ActionResult YearList()
        {
            if (HttpContext.Request.IsAjaxRequest())
                return Json(_bikeService.GetYears()
                           , JsonRequestBehavior.AllowGet);

            return RedirectToAction("Nop.Plugin.Search.Bikes.Views.BikeSearch.Index");
        }


Regards,

djperrott
11 years ago
When you said

I can load a partial view however I am unable to get to the controller using the route I have specified.

What did you mean by 'load a partial view', specifically how did you load it? :)
11 years ago
I Have copied the menu.cshtml file into our theme which has the following line:

 @Html.Partial("Nop.Plugin.Search.Bikes.Views.BikeSearch.Index") 


This loads the partial view and displays the box fine.

The javascript behind the box fires and tries to go for the controller, however it doesn't do anything and falls over when it tries to get the JSON data.

Regards,

djperrott
11 years ago
djperrott wrote:
I Have copied the menu.cshtml file into our theme which has the following line:

 @Html.Partial("Nop.Plugin.Search.Bikes.Views.BikeSearch.Index") 


This loads the partial view and displays the box fine.

The javascript behind the box fires and tries to go for the controller, however it doesn't do anything and falls over when it tries to get the JSON data.

Regards,

djperrott


Which means the part that really fails is the GetYears Action and not the Index action, am I right? Have you run a debug? Set a breakpoint anywhere inside GetYears, and see if it gets hit. :)
11 years ago
Your RedirectToAction uses the name of a view not an action?
(eg. Is "Nop.Plugin.Search.Bikes.Views.BikeSearch.Index" an action or the name of a view?)
sort of explains the error (302 for the redirect and 404 because the action is not found
11 years ago
When I try to debug the code the breakpoint doesn't get hit. I have amended the RedirectToAction however this is the point I have put the breakpoint on.

My expectation was that by trying to navigate to /Plugins/BikeSearch/ I should be hitting this breakpoint. Instead I get a 404 error.

below is the updated code

Regards,

djperrott


         public ActionResult Index()
        {

            return PartialView("Nop.Plugin.Search.Bikes.Views.BikeSearch.Index"); ;
        }

        // This collects the distinct years in the database, output is cached
        [OutputCache(Duration = 60, VaryByParam = "None")]
        public ActionResult YearList()
        {
            if (HttpContext.Request.IsAjaxRequest())
                return Json(_bikeService.GetYears()
                           , JsonRequestBehavior.AllowGet);

            return RedirectToAction("Index","BikeSearch");
        }
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.