Retrieving MenuItemTeaserImage using DocumentHelper.GetDocuments() for multiple page types

Tim G. asked on November 21, 2016 11:27

I'm trying to retrieve a dataset for 2 document types and within that display the MenuItemTeaserImage when bound to a repeater in aspx template but I never seem to be able to return this column. I'm using the code below which I thought was the right approach from the docs. Any help much appreciated.

var docs = DocumentHelper.GetDocuments()
.Type("MySite.PageType1", q => q.Columns("MenuItemName", "MenuItemTeaserImage"))
.Type("MySite.PageType2", q => q.Columns("MenuItemName", "MenuItemTeaserImage"))
.WithCoupledColumns(true);

Then in the repeater I have something like:

<ItemTemplate>
<a href="~<%# Eval("NodeAliasPath") %>">
<%# Eval("DocumentName") %>
<%# Eval("MenuItemTeaserImage") %>
</a>
</ItemTemplate>

Recent Answers


Roman Hutnyk answered on November 21, 2016 11:58

Try to specify columns to return:

var docs = DocumentHelper.GetDocuments()
.Columns(new List<string>() { "MenuItemName", "MenuItemTeaserImage" })
.Type("MySite.PageType1", q => q.Columns("MenuItemName", "MenuItemTeaserImage"))
.Type("MySite.PageType2", q => q.Columns("MenuItemName", "MenuItemTeaserImage"))
.WithCoupledColumns(true);

Not sure you even need WithCoupledColumns there...

0 votesVote for this answer Mark as a Correct answer

Tim G. answered on November 21, 2016 12:01

Thanks for the quick reply but using the above code I still get an exception:

DataBinding: 'CMS.DocumentEngine.TreeNode' does not contain a property with the name 'MenuItemTeaserImage'.

0 votesVote for this answer Mark as a Correct answer

Andy T answered on November 21, 2016 12:36

Hi Tim,

This column exist in Content_MenuItem table, so you need to join it to your tables

0 votesVote for this answer Mark as a Correct answer

Tim G. answered on November 21, 2016 12:48

Thanks Andy but the column also appears to exist in my custom page type - can you give me an example of getting this working by joining the Content_MenuItem table?

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on November 21, 2016 16:58

Please make sure you've specified correct page types and column names in your query. Similar query works perfect here...

0 votesVote for this answer Mark as a Correct answer

Tim G. answered on November 21, 2016 17:34

I've double checked the page types and column names and they all seem correct. I'm using custom page types if that makes any difference (although these both work fine in a query with a single page type).

0 votesVote for this answer Mark as a Correct answer

Tim G. answered on November 22, 2016 18:01 (last edited on November 22, 2016 18:01)

Finally got this working - switching our 'var' for 'DataSet' resolved the remaining error:

DataSet docs = DocumentHelper.GetDocuments()
.Columns(new List<string>() { "MenuItemName", "MenuItemTeaserImage" })
.Type("MySite.PageType1")
.Type("MySite.PageType2")
.WithCoupledColumns(true);
1 votesVote for this answer Mark as a Correct answer

Joel Dahlin answered on November 1, 2017 03:30

@Tim G. Your answer of switching from var to DataSet worked for me too. Why?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.