Upgrade to 2.7 Custom Controller doesn't work

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
So I started from scratch with 2.70 and i opened the source, right clicked the Controllers folder in NOP.Web and went to "add controller" and named it StoreController with "Empty MVS controller" and hit add.

I then right clicked "View()" in the ActionResults section and went to Add View.

I left the name Index and i have Razor (cshtml) in the engine

Chose 2 column as my template

and hit Add

When i hit F5 and run it, and try to go to my /store link the page just blinks and changes the URL to localhost:8080/Store and the content of the page is the same...

please help
11 years ago
Create a route for your controller, inherit from BaseNopController
11 years ago
keesjan wrote:
Create a route for your controller, inherit from BaseNopController


My StoreController.cs looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Nop.Web.Controllers
{
    public class StoreController : BaseNopController
    {
        //
        // GET: /Store/

        public ActionResult Index()
        {
            return View();
        }

    }
}




in 2.65 it looked like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Nop.Web.Controllers
{
    public class StoreController : Controller
    {
        //
        // GET: /Store/

        public ActionResult Index()
        {
            return View();
        }

    }
}



neither version works....

if i go to http://localhost:2619/Store the page just flashes and goes to my "main page" if i go to "http://localhost:2619/Store/index" the page actually comes up...this is weird
11 years ago
dootchie wrote:
[...]
neither version works....

if i go to http://localhost:2619/Store the page just flashes and goes to my "main page" if i go to "http://localhost:2619/Store/index" the page actually comes up...this is weird

The URL "http://localhost:2619/Store/index" works because it matches the Default route ({controller}/{action}/{id}). Since 2.70 introduced id-less URLs for products, categories, and manufacturers, routes that aren't defined in RouteProvider are handled by the GenericUrl route (in GenericUrlRouteProvider), which treats the path part of the URL ('store') as a slug. In the case of "http://localhost:2619/Store", it tries to find a UrlRecord entry for 'store', and when an entry isn't found, you are directed to the home page (Home/Index action).

Therefore, as was stated above, you need to create a route.

Add the following to Presentation\Nop.Web\Infrastructure\RouteProvider.cs
  routes.MapRoute("store",
                  "store",
                  new { controller = "Store", action = "Index" },
                  new[] { "Nop.Web.Controllers" });
.
11 years ago
mb wrote:
[...]
neither version works....

if i go to http://localhost:2619/Store the page just flashes and goes to my "main page" if i go to "http://localhost:2619/Store/index" the page actually comes up...this is weird
The URL "http://localhost:2619/Store/index" works because it matches the Default route ({controller}/{action}/{id}). Since 2.70 introduced id-less URLs for products, categories, and manufacturers, routes that aren't defined in RouteProvider are handled by the GenericUrl route (in GenericUrlRouteProvider), which treats the path part of the URL ('store') as a slug. In the case of "http://localhost:2619/Store", it tries to find a UrlRecord entry for 'store', and when an entry isn't found, you are directed to the home page (Home/Index action).

Therefore, as was stated above, you need to create a route.

Add the following to Presentation\Nop.Web\Infrastructure\RouteProvider.cs
  routes.MapRoute("store",
                  "store",
                  new { controller = "Store", action = "Index" },
                  new[] { "Nop.Web.Controllers" });
.


WORKED!! and thanks for the explanation!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.