【问题标题】:no overload for method takes 0 arguments, what am i missing?方法没有重载需要 0 个参数,我错过了什么?
【发布时间】:2014-01-31 13:04:29
【问题描述】:

我有一个连接到我的 MVC NopCommerce 应用程序中的按钮的方法。我只需要在调试器中得到结果,不需要在视图中显示结果。该方法位于 OrderServiceReport 类中。

问题是当我在控制器类中调用我的方法时,我得到:“方法没有重载需要 0 个参数”。认为我可能需要在此处添加参数?

这是我的代码..

IOrderReportService:

IList<BestsellersReportLine> DailyBestsellersReport(DateTime? startTime,
    DateTime? endTime, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss,
    int billingCountryId = 0,
    int recordsToReturn = 5, int orderBy = 1, int groupBy = 1, bool showHidden = false);

OrderReportService 类:

public IList<BestsellersReportLine> DailyBestsellersReport(DateTime? startTime,
        DateTime? endTime, OrderStatus? os, PaymentStatus? ps, ShippingStatus? ss,
        int billingCountryId = 0,
        int recordsToReturn = 5, int orderBy = 1, int groupBy = 1, bool showHidden = false)
    {



        int? orderStatusId = null;
        if (os.HasValue)
            orderStatusId = (int)os.Value;

        int? paymentStatusId = null;
        if (ps.HasValue)
            paymentStatusId = (int)ps.Value;

        int? shippingStatusId = null;
        if (ss.HasValue)
            shippingStatusId = (int)ss.Value;


        var query1 = from opv in _opvRepository.Table
                     join o in _orderRepository.Table on opv.OrderId equals o.Id
                     join pv in _productVariantRepository.Table on opv.ProductVariantId equals pv.Id
                     join p in _productRepository.Table on pv.ProductId equals p.Id
                     where (!startTime.HasValue || startTime.Value <= o.CreatedOnUtc) &&
                     (!endTime.HasValue || endTime.Value >= o.CreatedOnUtc) &&
                     (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) &&
                     (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) &&
                     (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) &&
                     (!o.Deleted) &&
                     (!p.Deleted) &&
                     (!pv.Deleted) &&
                     (billingCountryId == 0 || o.BillingAddress.CountryId == billingCountryId) &&
                     (showHidden || p.Published) &&
                     (showHidden || pv.Published)
                     select opv;


        var query2 = groupBy == 1 ?
            //group by product variants
               from opv in query1
               group opv by opv.ProductVariantId into g
               select new
               {
                   EntityId = g.Key,
                   TotalAmount = g.Sum(x => x.PriceExclTax),
                   TotalQuantity = g.Sum(x => x.Quantity),
               }
               :
            //group by products
               from opv in query1
               group opv by opv.ProductVariant.ProductId into g
               select new
               {
                   EntityId = g.Key,
                   TotalAmount = g.Sum(x => x.PriceExclTax),
                   TotalQuantity = g.Sum(x => x.Quantity),
               }
               ;

        switch (orderBy)
        {
            case 1:
                {
                    query2 = query2.OrderByDescending(x => x.TotalQuantity);
                }
                break;
            case 2:
                {
                    query2 = query2.OrderByDescending(x => x.TotalAmount);
                }
                break;
            default:
                throw new ArgumentException("Wrong orderBy parameter", "orderBy");
        }

        if (recordsToReturn != 0 && recordsToReturn != int.MaxValue)
            query2 = query2.Take(recordsToReturn);

        var result = query2.ToList().Select(x =>
        {
            var reportLine = new BestsellersReportLine()
            {
                EntityId = x.EntityId,
                TotalAmount = x.TotalAmount,
                TotalQuantity = x.TotalQuantity
            };
            return reportLine;
        }).ToList();



        return result;

    }

订单控制器类:

public ActionResult SendDailyReport()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
                return AccessDeniedView();

            try
            {
                _orderReportService.DailyBestsellersReport();


            }
            catch (Exception ex)
            { }
            return RedirectToAction("List");
        }

查看:

<a href="@Url.Action("SendDailyReport")" class="t-button">@T("Admin.Common.DailyBestsellersSend.All")</a>

怎么了??

谢谢

【问题讨论】:

  • 那构建?您在签名中有“可为空”的引用类型。
  • 错误很明显,你试图调用一个带有一些参数的方法,但你没有传递任何参数。你的大部分代码与实际问题无关

标签: c# asp.net-mvc entity-framework nopcommerce


【解决方案1】:

方法没有重载需要 0 个参数,我缺少什么?

参数,就像错误解释的那样。

需要为没有默认值 (= 42) 的参数提供一个值,对于可空值类型或引用类型,该值可能是 null

如果您查看生成的 WCF 客户端代理代码(或者您如何调用此服务),您可以看到它需要哪些参数以及可用的重载(如果有)。

从界面上看,至少前五个需要一个值:

_orderReportService.DailyBestsellersReport(null, null, null, null, null);

但我不确定您使用的客户端是否也接受这一点,或者它是否需要设置 all 参数。

您可能还想考虑使用数据协定而不是这么多参数。

【讨论】:

    【解决方案2】:

    你有没有默认值的参数。

    它们可以为空这一事实并不会改变您在调用方法时需要为这些参数添加一些东西的事实。

    如果您希望能够在不添加参数的情况下调用您的方法,请使用

    IList<BestsellersReportLine> DailyBestsellersReport(DateTime? startTime = null,
        DateTime? endTime = null, OrderStatus? os = null, PaymentStatus? ps = null, ShippingStatus? ss = null,
        int billingCountryId = 0,
        int recordsToReturn = 5, int orderBy = 1, int groupBy = 1, bool showHidden = false);
    

    如果无论如何都需要传递这些参数,请在调用方法时传递它们

    xxx.DailyBestsellerReport(null, null, null, null, null)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      相关资源
      最近更新 更多