Tarks
Tarks

Reputation: 4237

Getting Items from an Orchard CMS Custom Content Type object

We've created a custom Type in orchard through the Admin page, it has fields on it. How can I get access to those fields in a module?

The way I can find to do it is:

   dynamic firstCourse = _contentManager.Query().ForType("Course").List().First();
   var fields = firstCourse.Parts[5].Fields as List<ContentField>;

This is can't be the right solution.

Upvotes: 0

Views: 1703

Answers (1)

Bertrand Le Roy
Bertrand Le Roy

Reputation: 17814

dynamic firstCourse = _contentManager.Query("Course").List().First();
var myField = firstCourse.Course.MyField as WhateverTypeTheFieldIs;

This should do the trick to get the field called "MyField" but your question is unclear about what exactly you're trying to do. If you're trying to get the list of all fields, then this should work, I think:

var fields = firstCourse.Course.Fields as IEnumerable<ContentField>;

(also, you are more likely to get a good answer if you don't insult the people most likely to provide it. The documentation is open source, so go and fix it.)

Upvotes: 1

Related Questions