c# 4.0 - How to assign a value to an Orchard ContentPickerField from code? -


i working on orchard site needs able use customized forms create new content items.

to handle i'm using controller display form , trying create new content items on post populating dynamic items , sending them through contentmanagerservice's create() function.

this working ok until got content picker field have part of content item.

in project have content type of question record has submittedby field content picker field.

here can see in immediate window while processing post back:

      > dynamic q = _questionservice.newquestion("why doesn't work?");     {custom.website.models.question}         base {orchard.contentmanagement.contentpart}: {custom.website.models.question}         isnew: true         originalquestion: "why doesn't work?"         summary: null     > q.questionrecord     {orchard.contentmanagement.contentpart}         base {system.dynamic.dynamicobject}: {orchard.contentmanagement.contentpart}         contentitem: {orchard.contentmanagement.contentitem}         fields: count = 5         id: 0         partdefinition: {orchard.contentmanagement.metadata.models.contentpartdefinition}         settings: count = 0         typedefinition: {orchard.contentmanagement.metadata.models.contenttypedefinition}         typepartdefinition: {orchard.contentmanagement.metadata.models.contenttypepartdefinition}         zones: {orchard.ui.zonecollection}     > q.questionrecord.submittedby     {orchard.contentpicker.fields.contentpickerfield}         base {orchard.contentmanagement.contentfield}: {orchard.contentpicker.fields.contentpickerfield}         contentitems: null         ids: {int[0]} 

the contentitems property read-only , ids when assigning new int[] ids array system.objectdisposedexception message: instances cannot resolved , nested lifetimes cannot created lifetimescope has been disposed.

are there workarounds value set in code or need create own property store related content item ids? helpful have admin interface of contentpickerfield available.

thanks.

if have reference contentpickerfield, can assign value using ids property. in example (assuming content type has part called question has field called submittedby):

var submittedbyfield = ((dynamic)q.contentitem).question.submittedby; sbmittedbyfield.ids = new[] { submittedbyid }; 

as bertrand mentioned, format access content field is: contentitem.partname.fieldname. if attached field type directly via admin, part name has same name type name, hence contentitem.typename.fieldname (where typename name of implicitly created part).


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -