Pato
Pato

Reputation: 679

Orchard: Why is my property not saved?

I'm working in the following Orchard code. For any reason, I can't get my property ProductsContent persisted on DB. I have rendered properly the text fields for it on the View, and created the migrations accordingly. The Leaves property of my Product part record is being stored properly, but my ProductsContent property is not.

Upvotes: 0

Views: 46

Answers (1)

devqon
devqon

Reputation: 13997

Seems to me because you are using a viewmodel in your driver instead of the actual part, the part isn't updated automatically:

protected override DriverResult Editor(
    ProductPart part,
    IUpdateModel updater,
    dynamic shapeHelper)
{

    var model = new EditLeavesViewModel<ProductLeafEntry>();
    if (updater.TryUpdateModel(model, Prefix, null, null))
    {
        // set the property manually here
        part.ProductsContent = model.ProductsContent;

        if (part.ContentItem.Id != 0)
        {
            _productService.UpdateLeavesForContentItem(
                part.ContentItem, model.Leaves);
        }
    }

    return Editor(part, shapeHelper);
}

Upvotes: 2

Related Questions