"The parameters dictionary contains a null entry" while adding a widget

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 年 前
Hi everyone.
I want to add data to the order details in admin section. Because I want to minimize changes of the core code I've decided to add a widget calling in view and create a widget.
So in file _OrderDetails.Shipping.cshtml I've added:

@Html.Widget("order_shipping_info_bottom", Model.Id)


Widget has following methods implemented:

        public void GetDisplayWidgetRoute(string widgetZone, out string actionName, out string controllerName,
            out RouteValueDictionary routeValues)
        {
            controllerName = "ShoppingCartWeight";
            routeValues = new RouteValueDictionary
            {
                {"Namespaces", "Nop.Plugin.Ralfeus.ShoppingCartWeight.Controllers"},
                {"area", null},
                {"widgetZone", widgetZone}
            };

            switch (widgetZone)
            {
                case "order_summary_cart_footer":
                    actionName = "Cart";
                    break;
                case "productdetails_before_collateral":
                    actionName = "ProductDetails";
                    break;
                case "order_shipping_info_bottom":
                    controllerName = "AdminOrderWeight";
                    actionName = "OrderShipping";
                    break;
                default:
                    actionName = null;
                    break;
            }

        }

        [ChildActionOnly]
        public ActionResult OrderShipping(int orderId)
        {
            var primaryWeight = this._measureService.GetMeasureWeightById(this._measureSettings.BaseWeightId);
            var order = _orderService.GetOrderById(orderId);
            decimal orderWeight = 0;
            foreach (var orderItem in order.OrderItems)
            {
                var product = _productService.GetProductById(orderItem.ProductId);
                orderWeight += product.Weight;
            }
            var model = new ShoppingCartWeightModel
            {
                Weight =
                    $"{orderWeight:N0} {primaryWeight.Name}"
            };
            return PartialView("~/Plugins/Ralfeus.ShoppingCartWeight/Views/AdminOrderWeight/_Shipping.cshtml", model);
        }


When I try to open order details page I get following exception:
The parameters dictionary contains a null entry for parameter 'orderId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult OrderShipping(Int32)' in 'Nop.Plugin.Ralfeus.ShoppingCartWeight.Controllers.AdminOrderWeightController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters


I've checked that while calling widget order ID is passed. What could go wrong?
6 年 前
are you passing it as 'orderId' and not id? check your route to ensure the parameter name is correct.
6 年 前
I'm not passing a parameter by name at all. I just pass a value:
@Html.Widget("order_shipping_info_bottom", Model.Id)


I saw same widget call in core code and used it actually in same plugin:
Here widget is called in ProductTemplate.Simple.cshtml:
@Html.Widget("productdetails_before_collateral", Model.Id)

and here I implement widget for this call:

        public void GetDisplayWidgetRoute(string widgetZone, out string actionName, out string controllerName,
            out RouteValueDictionary routeValues)
        {
            controllerName = "ShoppingCartWeight";
            routeValues = new RouteValueDictionary
            {
                {"Namespaces", "Nop.Plugin.Ralfeus.ShoppingCartWeight.Controllers"},
                {"area", null},
                {"widgetZone", widgetZone}
            };

            switch (widgetZone)
            {
                case "order_summary_cart_footer":
                    actionName = "Cart";
                    break;
                case "productdetails_before_collateral":
                    actionName = "ProductDetails";
                    break;
                case "order_shipping_info_bottom":
                    controllerName = "AdminOrderWeight";
                    actionName = "OrderShipping";
                    //routeValues["area"] = "Admin";
                    break;
                default:
                    actionName = null;
                    break;
            }

        }

        [ChildActionOnly]
        public ActionResult ProductDetails(int productId)
        {
            var primaryWeight = this._measureService.GetMeasureWeightById(this._measureSettings.BaseWeightId);
            var product = _productService.GetProductById(productId);
            var model = new ShoppingCartWeightModel
            {
                Weight =
                    $"{product.Weight:N0} {primaryWeight.Name}"
            };
            return PartialView("~/Plugins/Ralfeus.ShoppingCartWeight/Views/ShoppingCartWeight/ProductDetails.cshtml", model);
        }


And this code works just fine. I see no difference between my call of widget and this one.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.