Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while retrieving Categories from XML in Tridion (DD4T - MVC)

Tags:

tridion

dd4t

In a DD4T View I am trying to pick the value of Path of the keyword inside the Category.

foreach(var category in @Model.Categories)
{
    if (category.Title.Contains("Taxonomy"))
    {
        str = category.Keywords[0].Path;            

        break;
    }
}

but getting null in @Model.Categories.

Error: Object reference not set to instance of the object.

Although data exist in XML.

Please suggest.

like image 738
Meenakshi Avatar asked Dec 05 '22 15:12

Meenakshi


1 Answers

I discovered this is an issue in DD4T. The work-around is quite simple: if you use the implementation of Component (or Page) as your model, rather than the interface, it works.

So start your view with:

@model DD4T.ContentModel.Component

Rather than

@model DD4T.ContentModel.IComponent

And try again.

like image 55
Quirijn Avatar answered Jun 03 '23 03:06

Quirijn