AI OnAI Off
If the css class is static and not changed per block you can use
ChildrenCssClass parameter in propertyfor method. Example if you have content area property called Teasers and want to change both wrapping tag for each block and css class on each block
@Html.PropertyFor(x => x.Teasers, new { ChildrenCustomTagName ="span", ChildrenCssClass = "block" })
Read more on options for rendering content areas here:
If you need block specific css class, it's easiest to put it in the partial view for the block instead. It's also possible to override the default content area renderer if you feel really trigger happy but I would stay away from that since it makes maintaining the solution more difficult.
I want to apply a specific style to all the blocks within the contentarea.
Model.cs:
public virtual ContentArea contentArea { get; set; }
Block.cs:
public virtual string Heading { get; set; }
public virtual XhtmlString Description { get; set; }
In the view, I am rendering as
@Html.PropertyFor(x => x.CurrentPage.contentArea)
In the above case, class is applied to the contentArea, but I want to apply the class to each block not to contentArea. I tried as below, but nothing is rendered in the contentarea.
@if(Model.CurrentPage.SelfServiceContentArea.Items.Any())
{
foreach(var item in Model.CurrentPage.SelfServiceContentArea.Items)
{
@item
}
}