I'm using Sitecore 8.2 with MVC, and want to know the correct way to make a select
element editable in Experience editor.
Following the instructions here -
created a custom button "Edit City" in core database, but it isn't showing up in Editor when this rendering is selected. The binding works fine in preview mode.
When the page is opened in Exp.Editor, there are 10 rows (I have 10 cities) under that dropdown, that say {"commands":[{"click::"chrome:common:edititem.....
Followed these steps to render the element.
controller:
public ActionResult RenderCitySelector()
{
IEnumerable<Item> cities = ItemExtensions.GetDatasource().Children;
return View("~/Views/cities.cshtml", cities);
}
View:
@model IEnumerable<Item>
using (Html.BeginEditFrame(Html.Sitecore().CurrentRendering.DataSource,
"/sitecore/content/Applications/WebEdit/Edit Frame Buttons/Custom Buttons/Edit City"))
{
<select id="ddlCity">
@if (Sitecore.Context.PageMode.IsExperienceEditorEditing)
{
foreach (Item city in Model)
{
<option value="@Html.Sitecore().Field(Templates.Fields.CityCode, city)">
@Html.Sitecore().Field(Templates.Fields.CityName, city)
</option>
}
}
else
{
foreach (Item city in Model)
{
<option value="@city.Fields[Templates.Fields.CityCode].Value">
@city.Fields[Templates.Fields.Cityname].Value
</option>
}
}
</select>
}
IEnumerable<Item> cities = ItemExtensions.GetDatasource().Children;'
So, you need to use editframe inside the foreach loop setting the current child as DataSource.foreach (var childItem in Model.Children) { using (BeginEditFrame({Button Folder}, childItem.FullPath)) { {Markup} } }
check this link