【问题标题】:Returning a list of categories nopCommerce返回类别列表 nopCommerce
【发布时间】:2012-10-09 11:35:43
【问题描述】:

我正在尝试使用 nopCommerce 返回 2 个列表,这两个列表都是只读的, 我正在寻找最简单的方法,因为我正在编写一个地铁应用程序,我真的不想花几周时间学习 MVC 。 第一个列表是来自基础 nopCommerce 平台的类别列表,第二个列表是产品列表。 两个列表都需要以 JSON 格式返回给调用客户端。

我有两个问题:

  1. 有没有一种方法可以在不调用自定义代码的情况下获取此列表?
  2. 我用下面的代码写了一个插件

    using System.Collections;
    using System.Collections.Generic;
    using System.Web.Mvc;
    using Nop.Core;
    using Nop.Core.Domain.Catalog;
    using Nop.Services.Catalog;
    using Nop.Services.Customers;
    using Nop.Core.Plugins;
    
    namespace Nop.Plugin.Other.ONWWW.Controllers
    {
        public class ONWWWController : Controller
        {
            public  ICategoryService _categoryService;
    
            public ONWWWController(ICategoryService categoryService)
            {
                this._categoryService = categoryService;
            }
    
            public ActionResult Index()
            {
                return Json(_categoryService.GetAllCategories(), JsonRequestBehavior.AllowGet);
            }
    
        }
    
    }
    

    为什么,当我运行代码时,出现以下错误?

    没有为此对象定义无参数构造函数。

【问题讨论】:

    标签: asp.net-mvc nopcommerce


    【解决方案1】:

    问题 1:您最好的选择是原始源代码中的 Nop.Plugin.Misc.WebServices 插件。

    问题 2:你有没有看到你唯一的构造函数是

    public ONWWWController(ICategoryService categoryService)
    

    哪个必须接受参数?换句话说,您没有正确注册依赖项。尝试查看任何默认插件中的 DependencyRegistrar.cs 文件之一。例如,Nop.Plugin.Misc.MailChimp 插件有一个您可以参考的 DependencyRegistrar.cs

    :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多