2012-10-09 37 views
0

我想使用nopCommerce返回2個列表,這兩個列表都是隻讀的, 我正在尋找最簡單的方法來做這件事,因爲我正在編寫一個地鐵應用程序,而我並不真的想花數週時間學習MVC。 第一個列表是從所述基部nopCommerce平臺類別的列表,第二列表是產品的列表。 這兩個列表都需要作爲JSON返回給調用客戶端。返回類別列表nopCommerce

我有兩個問題:

  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

問題1:你最好的選擇是在原始的源代碼的Nop.Plugin.Misc.WebServices插件。

問題2:你看到你有唯一的構造是

public ONWWWController(ICategoryService categoryService) 

必須接受一個參數?換句話說,你沒有正確註冊依賴關係。嘗試尋找在DependencyRegistrar.cs文件中的任何默認插件之一。該Nop.Plugin.Misc.MailChimp插件,例如,有一個DependencyRegistrar.cs,你可以參考。

:)