Meredori
Meredori

Reputation: 131

How do I enable delete when using Html.Sitecore().ItemRendering()?

I have looked around the internet for a solution to this and just cant seem to find anything that will help.

    @foreach (Sitecore.Data.Items.Item child in Html.Sitecore().CurrentItem.Children)
{
    @Html.Sitecore().ItemRendering(child)
}

This is the code pointing to a view rendering which in turn outputs very basic details.

<h3>@Html.Sitecore().Field("Question")</h3>
<div>
    @Html.Sitecore().Field("Comment")
</div>

I have gotten this to Render correctly and can edit each part individually "Question" or "Comment" text, but I am looking to add a way to delete the entire item from the original page using the page editor.

I tried adding the "delete" button to the rendering but it did not show up.

Any help would be appreciated greatly!

Upvotes: 0

Views: 307

Answers (2)

Ian Graham
Ian Graham

Reputation: 3216

When you have a listing of sitecore items and you need to remove an item from a list in the Page Editor then edit frames can be useful.

This example here shows how you can add an interface to remove an item from a multilist which will then affect the rendering of items.

https://briancaos.wordpress.com/2011/11/28/using-sitecore-editframe-in-pageedit/

To get edit frames working with mvc: https://visionsincode.wordpress.com/2015/01/08/how-to-use-editframe-in-sitecore-mvc/

Upvotes: 1

Varun Nehra
Varun Nehra

Reputation: 379

What your are doing is outputting markup iteratively using an HTML helper provided by Sitecore which is not the same as outputting the layout definition for the item that allows the page editor to inject the appropriate chromes for managing the presentation of an item.

It's similar to creating a search results listing and expecting the page editor to allow the user to remove an item from the listing using page editor which is not possible as it is dynamically generated markup and not a set of renderings stored as presentation for the item.

Upvotes: 0

Related Questions