Jorge Valle

Jorge Valle

Jorge Valle is a front end developer with a particular passion for, and expertise in, JavaScript and user interfaces. Lately, he's also been diving into machine learning.

Updating custom parts and fields through code in Orchard CMS

One of my favorite aspects of working with Orchard CMS is the ability to easily create tailored content types and fields. Through the admin UI, you can create custom content types, attach custom parts to them, and then attach custom fields to these parts.

What happens when you want to update these field values through code, though? I recently ran into a situation where I needed to do exactly that. The trigger was a POST request that was firing from an Orchard workflow. Once fired, a content item was created, and these fields were populated with values from a form that sent along JSON.

When you are working with custom parts and fields, you can't use the same syntax as with core parts.

Typically, for a Title Part, you could do this:

However, for custom parts, you must first cast them as dynamic, and then use dot notation to access the values.

Here's an edited version of the controller, without error checking. Notice that the content item needs to be created first, before you update the field values.


Books, patrons and coffee in Caffè San Marco, Trieste