簡體   English   中英

AmbiguousMatchException:行動要求不明確

[英]AmbiguousMatchException: Request for action is ambiguous

編輯-問題解決了!

升級尚未更新System.Web.Mvc的程序集引用。

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>

/編輯

我正在運行DNN網站+ Webshop(Hotcakes),並且最近都升級了[DNN 7.4.2-> 8.0.3,HCC 1.10.4 Pro-> 03.02.00]。

除了一個問題,我設法解決了所有問題:

“ System.Reflection.AmbiguousMatchException:控制器類型為'CartController'的當前對操作'Index'的請求在以下操作方法之間是模棱兩可的:類型為Hotcakes.Modules.Core.Controllers.CartController的System.Web.Mvc.ActionResult IndexPost()類型Hotcakes.Modules.Core.Controllers.CartController上的System.Web.Mvc.ActionResult Index()

我發現了各種問題,包括路由:以下兩種行動方法之間的當前行動要求不明確 ,但是沒有找到解決方案。

根據我所學,這應該沒問題-相同的ActionName,一個Get,一個Post。 沒有其他稱為Index或IndexPost的方法。 我想念什么? 另外,由於DNN控制-> no Global.asax.cs,因此我無法使用MapRoutes。

動作方法:

    #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);
    }

風景:

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});
        }
    }
}

發布屬性:

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);
        }
    }
}

這兩個方法具有相同的名稱,因為用[ActionName(“ Index”)]裝飾了IndexPOST,所以現在它們都具有路由/ YourController / Index。

更改屬性值,或更改方法Index()的名稱(第一個)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM