使用Glass Mapper从Sitecore访问数据时出现问题



我在内容树中有子项,如下所示,必须显示在同一页面中。我们为页面创建了一个类型为ModelA的Stronglytyped视图:

public class ModelA
{
        public IEnumerable<ModelA > item1 { get; set; }
        public IEnumerable<ModelB> item2{ get; set; }
}

内容树是:

Item1(Based on Template A and Created ModelA to access)
---Children11(Based on Template A and Created ModelA to access))
---Children12(Based on Template A and Created ModelA to access))
Item2(Based on Template A and Created ModelA to access))
---Children21(Based on Template B and Created ModelB to access))
---Children22(Based on Template B and Created ModelB to access))

我们使用GlassMapper来获取数据,因此我们为Children11Children12定义了ModelA,为Children21Children22定义了ModelB

我可以为item1获得孩子,但不能为item2获得孩子,因为它是null。是因为玻璃映射器无法找到它们并映射类型为ModelB吗?

我认为您必须在属性上使用SitecoreChildren属性才能使其工作。。。

最新更新