Error retrieving categories from XML in Tridion (DD4T - MVC)

In the DD4T view, I am trying to select a path value for a keyword within a 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: The reference to the object is not installed in the instance of the object.

Although the data exists in XML.

Please offer.

+4
source share
5 answers

I found this to be a problem in DD4T. The workaround is quite simple: if you use the Component (or Page) implementation as your model, and not an interface, it works.

So start your scan with:

 @model DD4T.ContentModel.Component 

Instead

 @model DD4T.ContentModel.IComponent 

And try again.

+7
source

I registered this as a problem on the Google Code DD4T site here .

This seems to be because contravariance is not supported by List and IList, which means strings like:

 IList<ICategory> IComponent.Categories { get { return Categories as IList<ICategory>; } } 

in class ContentModel will never work. The suggestion of digging around is to change this to IEnumerable, which supports contravariance.

+4
source

His work after the introduction of Quirijn Component c = (Component) Model; c.Categories [0] ...

Thanks Vikas Kumar

+3
source

Have you published your categories for your purpose?

+2
source

Yes, first make sure that you publish the categories to the broker's database. The path The page or XML component is deserialized into an IPage or IComponent object is pretty simple.

Also indicate which version of DD4T you are using. I remember that there was a problem with deserialization in earlier versions.

0
source

All Articles