Reputation: 1710
I have a Web API service that I have managed to use to pull values into a ContentPart
by using the method outlined here: How to change Orchard record repository.
Now, what I want to do is update the values of the properties on my ContentPart
and have the update performed via a Web API call. I think I'm close, but just can't get an update method to fire.
In my Handler
, I have added a handler for OnUpdate
. I can see my OnUpdate
method get registered, but it never executes.
So my question is: Is this the correct handler event to use? And if so, how can I get it to trigger?
I should add that I am accessing the ContentPart
through a Controller
, as opposed to a Driver
.
Upvotes: 1
Views: 303
Reputation: 13366
OnUpdating
/ OnUpdated
get fired whenever you call IContentManager.UpdateEditor(item)
. In the default scenario this happens when you hit "Save" button when editing your content item.
I don't quite get what you mean by "accessing the ContentPart
through a Controller
"?
Do you have a custom controller that handles the item editor rendering and it's postback? Or are you creating and updating some items in code, without using the built-in editors at all?
IContentEditor.UpdateEditor(item)
gets called for the whole content
item inside the POST action (same way it does in the default
controller - Core\Contents\Controllers\AdminController.cs
).OnUpdating
/
OnUpdated
won't be fired and you need to call the web service on
your own from the controller action, as Bertrand pointed out in the comments.There is also a third option available and I found it particularly useful in similar cases:
LazyField<T>
as a backing field for those part properties you need to push to web service after update.OnActivated
event).For examples how to work with lazy fields take a look into CommonPartHandler
class and methods LazyLoadHandlers
and PropertySetHandlers
.
Upvotes: 1