2
votes

I've looked everywhere for this but can't seem to find exactly what I'm looking for. I'm trying to render a content part shape from an MVC controller using AJAX, but I'm having trouble rendering the shape, which I hope somebody can help with.

I've tried using the 'BuildDisplay' method on the content manager by passing it the content part, but it creates the shape for the item that was returned from my Content Manager query. I've also tried using 'BuildDisplayShape', passing in ContainerPart as T and the item returned from the Content Manager query.

Using Ajax, I'm passing custom id number to my controller. In the controller action, I'm using the Content Manager to query for and return the first item that matches. The item that is returned will always have a container part. I want to take the found item's container part and build the shape that renders the contained items and then return it back to my view where it will be displayed.

    [HttpGet]
    public ActionResult ReturnChildren(int id)
    {
        var parent = _contentManager.Query<ItemPart, ItemPartRecord>().Where(o => o.ItemId == id).List().FirstOrDefault();
        ContainerPart container = null;

        if (parent != null)
        {
            container = parent.As<ContainerPart>();
        }

        if (container == null)
        {
            return null;
        }


        var shape = _contentManager.BuildDisplay(container, "Summary");

        // shape = _contentManager.BuildDisplayShape<ContainerPart>(container.Id, "Summary");
        // shape = _contentManager.BuildDisplay(container, "Summary");

        //return View("ItemSelector/ReturnChildren", shape);
        return new ShapeResult(this, shape);
    }

Cheers in advance for the help!

2

2 Answers

3
votes

I don't believe you can render just a single content part, only the whole content item. If you do just want a single content part displayed you could do something like...

var shape = _contentManager.BuildDisplay(container, "ContainerPartDisplay");

Then use your placement to hide all the rest of the parts/fields apart from the ContainerPart...

<Match DisplayType="ContainerPartDisplay">
 <Place Parts_Title="-" />
 ...
</Match>

It feels a bit hack-y, but should give you what you want

0
votes

I ended adding a new view to contain exactly what I wanted to show and the created my own detail type which is handled in the part driver. As no other part uses my custom detail type, I don't have to hide anything other shapes. In the controller I was able to just do:

var shape = _contentManager.BuildDisplay(container, "myDetailType");

Thanks for your help though Hazza.