How to fetch custom field in Orchard?

Topics: Writing modules
Jun 3, 2011 at 1:25 PM

Hi,

I have added few custom fields to a User content type.

How to fetch those fields from the user content type using the ContentManager?

Best regards,

Ann

Coordinator
Jun 3, 2011 at 4:01 PM

var contentItem =...;
contentItem.PARTNAME.FIELDNAM.PROPERTY;

 

Jun 6, 2011 at 10:50 AM

Thanks,

Developer
Jun 6, 2011 at 1:51 PM

@Anna: But look out for naming issues - if the field is named the same as some property existing on that part - the field will be used instead (it has priority over existing properties).

Jun 6, 2011 at 2:06 PM

Also just a slight fix to sebastien's post; to access fields in that way you have to make sure the ContentItem is treated as dynamic:

dynamic contentItem =...;
contentItem.PARTNAME.FIELDNAME.PROPERTY;