AI OnAI Off
Quick and dirty:
@if (Model.CurrentPage.MainContentArea != null)
{
for (var i = 0; i < Model.CurrentPage.MainContentArea.FilteredItems.Count(); i++)
{
@Html.Raw("{ \"title\":\"" + Model.CurrentPage.MainContentArea.FilteredItems.ElementAt(i).GetContent().title + "\", \"order\":" + i + "\" }");
if (i < Model.CurrentPage.MainContentArea.FilteredItems.Count() - 1)
{
@Html.Raw(",<br/>");
}
}
}
We have a simple block (MyBlock) with a few string properties, and a view which simply outputs the properties as text.
e.g.
{ "title": "@Html.PropertyFor(x => x.title)" }
We have a page with a content area where you can create/drag/drop several of these blocks.
The view for the page simply outputs the content area thus:
@Html.PropertyFor(x => @Model.MyBlockContentArea)
We get:
{ "title":"some title"
}{ "title":"some title2" }
{ "title":"some title3" }
This works, but we now need to output an order field in each block, and a comma after all but the last.
{ "title":"some title"
, "order":1 },{ "title":"some title2", "order":2 },
{ "title":"some title3", "order":3 }
Presumably, in the page view, we need a way to itterate over the blocks in the content area, and output them programatically, and not render anything in the individual blocks views (i.e. the block has no view, it is only every viewed via its page).
Any idea the simplest way to do this?