Trying to Access content type field in Search results

Topics: Core, Customizing Orchard
May 15, 2013 at 2:59 PM
Edited May 15, 2013 at 3:00 PM
Hi There

I am trying to access the contentType of the items in the search results.
I am trying to count how many items for a particular content type.

But I am not sure how to access the property, Im trying to do it without changing the controller.

I am trying something like this

IEnumerable<object> searchResults = Model.ContentItems;
var articles = searchResults.Where(x => x.ContentType.Equals("BlogPost")).Count();

I have tried casting searchResults to ContentItem and a few other things with no luck.

any suggestion.

May 15, 2013 at 5:33 PM
If you look at the Index action method, you'll see that Model.ContentItems is a List shape, where each item is a display shape. These display shapes each contain a ContentItem property, which is the "real" content item. So you should be able to do something like this:
var articles = searchResults.Where(x => x.ContentItem.ContentType.Equals("BlogPost")).Count();
May 16, 2013 at 7:53 AM
Yeah I have tried that

get the following error object' does not contain a definition for 'ContentItem'

I think there is a cast or As<> needed.