Check if zone has no items

Topics: Customizing Orchard
Jul 8, 2011 at 9:49 AM

Is there a way how i can check if the zone conists of an empty shape?

I have the situation where the widget is sometimes empty because there is nothing to diplay and i don't want that the zone gets rendered. 

Jul 8, 2011 at 4:59 PM

You should check the Items property. It's an enumerable so you can use Any() on it.

Jul 8, 2011 at 5:36 PM

The zone might also not exist if nothing was added to it, in which case you’d need to see if it’s null.

For example (from TheThemeMachine’s Layout.cshtml)

@if (Model.AfterContent != null) {

<div id="after-content">




If there’s a chance the zone’s being defined but not filled then you’d also need to check for .Any()