返回类别列表nopCommerce

时间:2012-10-09 11:35:44

标签: asp.net-mvc nopcommerce

我正在尝试使用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);
            }
    
        }
    
    }
    

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

      

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

1 个答案:

答案 0 :(得分:1)

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

问题2:您是否看到唯一的构造函数是

public ONWWWController(ICategoryService categoryService)

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

:)