public override async Task<IDisplayResult> EditAsync(ContentItem model, IUpdateModel updater) { // This method can get called when a new content item is created, at that point // the query string contains a ListPart.ContainerId value, or when an // existing content item has ContainedPart value. In both cases the hidden field // needs to be rendered in the edit form to maintain the relationship with the parent. if (model.Is<ContainedPart>()) { return BuildShape(model.As<ContainedPart>().ListContentItemId); } var viewModel = new EditContainedPartViewModel(); if ( await updater.TryUpdateModelAsync(viewModel, "ListPart")) { // We are editing a content item that needs to be added to a container // so we render the container id as part of the form return BuildShape(viewModel.ContainerId); } return null; }
public override async Task<IDisplayResult> UpdateAsync(ContentItem model, IUpdateModel updater) { var viewModel = new EditContainedPartViewModel(); if (await updater.TryUpdateModelAsync(viewModel, "ListPart")) { model.Weld<ContainedPart>(); model.Alter<ContainedPart>(x => x.ListContentItemId = viewModel.ContainerId); } return await base.UpdateAsync(model, updater); }