我正在 nopcommerce 中创建一个新主题,
我想打印 View 中的所有类别,
我编写了以下代码来检索类别中的所有子类别,
此调用(第 2 行)失败,并出现对象引用未设置为 onject 的实例
错误。
var _engine = new NopEngine();
var categoryService = _engine.Resolve<ICategoryService>();
var L1Categories = from p in categoryService.GetAllCategoriesByParentCategoryId(24)
where (p.Deleted==false)
select p;
最佳答案
您应该使用以下代码来解析 ICategoryService:
var categoryService = EngineContext.Current.Resolve<ICategoryService>();
不要忘记添加适当的“using”指令
关于c# - 无法创建 NopEngine 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32412228/