Why isn't my Enumerable getting populated by Glass.Mapper?

若如初见. 提交于 2019-12-20 05:17:17

问题


I'm totally confused as to why this isn't working. I have a class with a list of other classes as a property of it:

public class Widget
{
     ....
     public virtual IEnumerable<WidgetButton> Buttons { get; set; }
}

[SitecoreType(TemplateId = "{B615973D-59F6-437E-9827-BA3A40068C69}", AutoMap =true)]
public class WidgetButton : BasePage
{
     [SitecoreField]
     public virtual string Title { get; set; }
}

My sitecore item has a TreeListEx with one item in it:

and I'm reading this item thus:

Widget widgetTest = SitecoreContext.GetItem<Widget>(new Guid("{4FF5B96F-9606-4581-95F7-B6A7BAA4C28F}"));

My Widget(widgetTest) contains all of the data out of sitecore, but the buttons!? The Buttons property is just an empty list. What am I missing I've tried several configurations, Publishing, etc. According to the Glass.Mapper tutorials this should work


Glass configuration

Glass.Mapper.Sc.CastleWindsor.config

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <pipelines>
            <initialize>
                <processor type="RR.Web.Website.App_Start.GlassMapperSc, RR.Web.Website" />
            </initialize>
        </pipelines>
    </sitecore>
</configuration>

Glass.Mapper.Sc.Mvc.Config

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
      <settings></settings>
    <pipelines>



      <mvc.getModel>
        <processor type="Glass.Mapper.Sc.Pipelines.Response.GetModel, Glass.Mapper.Sc.Mvc"/>
      </mvc.getModel>

    </pipelines>
  </sitecore>
</configuration>

Going directly to sitecore I can get my item:

Sitecore.Data.Database context = Sitecore.Context.Database;
var item  = context.GetItem(new ID("{4FF5B96F-9606-4581-95F7-B6A7BAA4C28F}"));

item contains a field called Buttons, the value of this field is the GUID of the item in the treelist ({3C18BF9F-9906-4807-83B9-73CA08E61C39}).

If I query this directly I can see the button:

var buttonItem = context.GetItem(new ID("{3C18BF9F-9906-4807-83B9-73CA08E61C39}"));

so everything appears perfectly fine! Why isn't glass mapper mapping this?


回答1:


I got a solution, don't ask me why this works because I found it though trial and error. Basically doing this seemed to make it work:

[SitecoreType(AutoMap =true)]
public class Widget
{
     ....
     [SitecoreField(FieldType =SitecoreFieldType.TreelistEx)]
     public virtual IEnumerable<WidgetButton> Buttons { get; set; }
}

specifically I think specifying the FieldType.



来源:https://stackoverflow.com/questions/33131161/why-isnt-my-enumerable-getting-populated-by-glass-mapper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!