This project is read-only.

How to Create Web API Controller for updating Content Items

Topics: Customizing Orchard
May 14, 2013 at 7:52 AM

I'm trying to create a web api controller that can update a Content Item.
Is this possible?

The code may probably look like this:
public void Put(int id)
            var info = _contentManager.Get(id);

            dynamic model = _contentManager.UpdateEditor(info, this);

            if (!ModelState.IsValid)

But the problem is that this code requires the web api controller to implement IUpdateModel.
Looking at some sample codes, the IUpdateModel implementation may look like this:
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties)
            return TryUpdateModel(model, prefix, includeProperties, excludeProperties);

        void IUpdateModel.AddModelError(string key, LocalizedString errorMessage)
            ModelState.AddModelError(key, errorMessage.Text);
But the problem with the above code is that it uses TryUpdateModel function from the Controller class which is missing in the ApiController class.

Please help on how I can accomplish this.