您好我正在使用glassmapper,我正在尝试阅读多列表中的所有项目并填充。
我的页面有一个导航,标题和一个多列表字段,我可以在其中选择项目。我的问题是,虽然我能够读取子项(count是> 0)属性值为null。但Sitecore的基本Item属性不为null
Fieldtype没有解决问题
这些是我的两个模型
public class Pagebase: ItemBase, INavigation
{
//Page Base
public string PageTitle { get; set; }
public string PageHeading { get; set; }
//Navigation
public string NavigationTitle { get; set; }
public string NavigationDescription { get; set; }
public IEnumerable<Pagebase> SubItems{ get; set; }
}
[SitecoreType(TemplateId = "{7BC902B5-305B-484A-9AD9-6AAEBA48BDD7}", AutoMap = true)]
public interface INavigation
{
[SitecoreField("Navigation Title")]
string NavigationTitle { get; set; }
[SitecoreField("Navigation Description")]
stringNavigationDescription { get; set; }
[SitecoreField("Sub Items")]
IEnumerable<Pagebase> SubItems{ get; set; }
}
我的观点是这样的
@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<xxx.Pagebase>
<div class-"test">
@Model.NavigationTitle // This has value
@Model.NavigationDescription // This has correct value
@Model.SubItems.Count // Show the correct number of Items selected in Multi list.
// The multilist is again a Pagebase type.
//When i do :
@foreach (var subItem in Model.SubItems)
{
@subItem.NavigationTitle //This is null
@subItem.NavigationDescription // This is null
@@subitem.Id / @subitem.Url / @subitem.Name / // This is not null
}
</div>
我错过了什么?
答案 0 :(得分:1)
在界面的实现类中,您需要将所有属性标记为虚拟。
另请参阅documentation of glassmapper
使用glassmapper rationale of using virtual properties。
因此,您的实现类将如下所示
public class Pagebase: ItemBase, INavigation
{
//Page Base
public virtual string PageTitle { get; set; }
public virtual string PageHeading { get; set; }
//Navigation
public virtual string NavigationTitle { get; set; }
public virtual string NavigationDescription { get; set; }
public virtual IEnumerable<Pagebase> SubItems{ get; set; }
}