在DD4T视图中,我试图在类别中选择关键字的Path值.
foreach(var category in @Model.Categories) { if (category.Title.Contains("Taxonomy")) { str = category.Keywords[0].Path; break; } }
但在@ Model.Categories中变为null.
Error: Object reference not set to instance of the object.
虽然数据存在于XML中.
请建议.
解决方法
我发现这是DD4T中的一个问题.解决方法非常简单:如果您使用Component(或Page)的实现作为模型,而不是接口,它就可以工作.
所以开始你的观点:
@model DD4T.ContentModel.Component
而不是
@model DD4T.ContentModel.IComponent
然后再试一次.