Ambiguous request error when inheriting from core controller

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

i'm currently writing a plugin in which i want to modify some behaviors of the shopping cart controller:

so this is what i did:

I made a new controller inheriting from ShoppingCartController, like:

public class MyOwnProductShoppingCartController : ShoppingCartController

and in the RouteProvider i did:

        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapLocalizedRoute("Plugin.NopSolutions.HandlingFeeProduct.ApplyDiscountCoupon",
                "cart/",
                new { controller = "MyOwnProductShoppingCart", action = "Cart" },
                new[] { "Nop.Plugin.NopSolutions.MyOwnProduct.Controllers" }
                );
        }

        public int Priority
        {
            get
            {
                return 2;
            }
        }


Then in the controller i added the following method:

        [ValidateInput(false)]
        [HttpPost, ActionName("Cart")]
        [FormValueRequired("applydiscountcouponcode")]
        public ActionResult MyOwnApplyDiscountCoupon(string discountcouponcode, FormCollection form)
        {
               //some code

         }



After installing my plugin, when i apply a discount i get the following error:

The current request for action 'Cart' on controller type 'HandlingFeeProductShoppingCartController' is ambiguous between the following action methods:
System.Web.Mvc.ActionResult MyOwnApplyDiscountCoupon(System.String, System.Web.Mvc.FormCollection) on type Nop.Plugin.NopSolutions.HandlingFeeProduct.Controllers.HandlingFeeProductShoppingCartController
System.Web.Mvc.ActionResult ApplyDiscountCoupon(System.String, System.Web.Mvc.FormCollection) on type Nop.Web.Controllers.ShoppingCartController

What am i doing wrong?
9 years ago
In fact you should really use Action Filter. http://www.pronopcommerce.com/overriding-intercepting-nopcommerce-controllers-and-actions
9 years ago
Thank you for the quick reply!
I was thinking about using action filters.
It's possible with them to skip the excecution of a method?
What i mean in my case is i.e. to skip the whole execution of the ApplyDiscount method and only use the code implementation in my action filter?
9 years ago
Yes of course, you just need to return different result (perhaps do a redirect to Cart), which would effectively bypass the original method.

You can, for example do:


filterContext.Result = new RedirectToRouteResult("SOME_ROUTE", routeValues)

/* OR */

filterContext.Result = new ViewResult
{
    ViewName = "VIEW_NAME",
    ViewData = filterContext.Controller.ViewData
};
6 years ago
Thanks Woon Cherk,

If you are in NOP 3.90 :: all the action method now has virtual keyword. So if you need to override it is simple to inherit the controller and then have your own override Action method.


public class OVSearchController : CatalogController
    {}


Action Method::

[ChildActionOnly]
        public override ActionResult SearchBox()
        {}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.