0

Edit - Problem solved!

The assembly reference for System.Web.Mvc has not been updated by the upgrade.

Web.config:

Broken:
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.1" />
  </dependentAssembly>
Fixed:
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
  </dependentAssembly>

/Edit

I'm running a DNN website + Webshop (Hotcakes) and recently upgraded both [DNN 7.4.2 -> 8.0.3, HCC 1.10.4 Pro -> 03.02.00].

I managed to fix all but one issue:

"System.Reflection.AmbiguousMatchException: The current request for action 'Index' on controller type 'CartController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult IndexPost() on type Hotcakes.Modules.Core.Controllers.CartController System.Web.Mvc.ActionResult Index() on type Hotcakes.Modules.Core.Controllers.CartController

I found various questions, including Routing: The current request for action [...] is ambiguous between the following action methods, but didn't find a solution.

According to what I've learned, this should be fine - same ActionName, one Get, one Post. There's no additional Method called Index or IndexPost. What am I missing? Also, I can't play around with the MapRoutes, since DNN is controlling that -> no Global.asax.cs.

The Action methods:

    #region Main Cart Actions

    // GET: /Cart/
    [NonCacheableResponseFilter]
    [HccHttpGet]
    public ActionResult Index()
    {
        var model = IndexSetup();
        HandleActionParams();
        CheckForQuickAdd();
        LoadCart(model);
        ValidateOrderCoupons();
        CheckFreeItems(model);

        if (ModuleContext != null && ModuleContext.Configuration.DesktopModule.ModuleName == "Hotcakes.Cart")
            HccApp.AnalyticsService.RegisterEvent(HccApp.CurrentCustomerId, ActionTypes.GoToCart, null);

        CheckForStockOnItems(model);
        return View(model);
    }

    // POST: /Cart/
    [ActionName("Index")]
    [HccHttpPost]
    public ActionResult IndexPost()
    {
        var model = IndexSetup();
        LoadCart(model);

        var intResult = CartIntegration.Create(HccApp).BeforeProceedToCheckout(HccApp, model);

        if (!intResult.IsAborted)
        {
            if (CheckForStockOnItems(model))
            {
                ForwardToCheckout(model);
            }
        }
        else
        {
            FlashWarning(intResult.AbortMessage);
        }

        return View(model);
    }

The view:

namespace Hotcakes.Modules.MiniCart
{
    public partial class MiniCartView : HotcakesModuleBase
    {
        protected override string RenderView()
        {
            var viewName = Convert.ToString(Settings["View"]);
            if (!string.IsNullOrEmpty(viewName))
                return MvcRenderingEngine.Render("Cart", "Index");
            return MvcRenderingEngine.Render("Cart", "Index", "MiniCart", new {MiniCart = true});
        }
    }
}

Post attribute:

namespace Hotcakes.Commerce.Extensions
{
    [AttributeUsage(AttributeTargets.Method)]
    public sealed class HccHttpPostAttribute : ActionMethodSelectorAttribute
    {
        // Fields
        private static readonly AcceptVerbsAttribute _innerAttribute = new AcceptVerbsAttribute(HttpVerbs.Post);

        // Methods
        public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
        {
            var hccRequestType = (string) controllerContext.RequestContext.RouteData.Values["hccrequesttype"];
            if (Factory.CreateHccFormRenderer().VirtualFormUsed && !string.IsNullOrEmpty(hccRequestType))
            {
                return hccRequestType == "hccpost";
            }
            return _innerAttribute.IsValidForRequest(controllerContext, methodInfo);
        }
    }
}
  • This doesn't occur on a clean installation of Hotcakes, so it sounds like you may have modified the source code? I wouldn't recommend doing that to any open source solution. :) – Will Strohl Jun 07 '18 at 19:42
  • The source code has not been modified - I just downloaded the source code in order to fix that issue. I'll try setting up a fresh installation, I guess something went wrong while upgrading. – Alois Krichmayr Jun 08 '18 at 05:46

1 Answers1

0

You have the two methods with the same name, because you decorated the IndexPOST with [ActionName("Index")], so now they both have the routing /YourController/Index.

Either change the attribute value, or change the name of the method Index() ( the first one)

Plexis Plexis
  • 302
  • 2
  • 12
  • 1
    Afaik that should not be a problem since you can have 2 action methods with the same name on a controller, as long as one is `[HttpPost]` and the other is `[HttpGet]` – Alois Krichmayr Jun 07 '18 at 11:04
  • @AloisKrichmayr Yes you can have them with the same name, but not the same signature! ( The name and the parameters number) – Plexis Plexis Jun 11 '18 at 13:14