Steps to adding a Controller

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
I needed to add a new action to the Shopping Cart controller in the Nop.Web project. So for that I created a new controller which inherits the ShoppingCartController. I made changes to the RouteProvider class so that it uses the new controller that I created instead of the default one.


routes.MapLocalizedRoute("AddProductToCart",
                            "cart/addproduct/{productId}",
                            new { controller = "MyNewShoppingCartController", action = "AddProductToCart" },
                            new { productId = @"\d+" },
                            new[] { "Nop.Web.Controllers" });

            routes.MapLocalizedRoute("ShoppingCart",
                            "cart/",
                            new { controller = "MyNewShoppingCartController", action = "Cart" },
                            new[] { "Nop.Web.Controllers" });


But now when I go to the shopping cart icon on the home page it complains that the resource that I am looking for is no longer available. Please somebody guide me if I am changing the routes at the right place or do I change the routes somewhere else.

Thanks
12 years ago
It's probably complaining about not being able to find the View.  Trying referencing the view explicitly and see if that helps.
12 years ago
Thanks AndyMcKenna for replying. I tried your suggestion but didn't help. I was trying to enable the route debugger in the web config file to see if I am being routed to the right controller but for some odd reason that is also not working. The website is displayed but no route table is displayed :(
12 years ago
Update: I did not know the route debugger information shows up only when you are in the admin section. So when I went to the admin section I was able to access the route table.

I did see the entrees for shopping cart and it shows that both the actions (displaying the cart and adding to cart) should be going to the new controller that I created. So routing doesn't seem to be the issue then. Any other suggestions you think might be able to solve my issue??
12 years ago
According to the ThemableRazorViewEngine, your view should be at /Views/{1}/{0}.cshtml where 1 is the Controller name and 0 and is the Action name.  Do those match up for you?
12 years ago
Thanks AndyMcKenna for pointing that out. That is the one of the basics of MVC and I forgot that.duh!!!

I do have another questions about the views for the new controller. As you said I will have to have a view folder named after my controller and then copy the views form the shopping cart views folder to the new views folder. But everytime there is new source code for nop commerce I will have to make sure the views in the default shopping cart controller will have to be copied to the my new views folder just to make sure I have the newest code for shopping cart views. Right?This kind of seems tedious. Is there a way around that??
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.