加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

从Tridion中的XML检索类别时出错(DD4T – MVC)

发布时间:2020-12-16 23:25:54 所属栏目:百科 来源:网络整理
导读:在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
在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

然后再试一次.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读