This project is read-only.

Easy way to determine if all field values are null?

Topics: Customizing Orchard, Writing themes
Dec 13, 2013 at 3:59 PM
I'm working on writing an item template for a content type that contains multiple optional fields. In my file, I'm putting all those fields into a separate zone. I would like to display that zone only if any of the field values is not null. However, I'm unable to figure out how to determine if that's the case.

I tried getting the fields from Model.ContentItem.[contenttype].Fields and cast that to List<Orchard.ContentManagement.ContentField>, but ContentField doesn't define Value; that's defined in each of the individual field types.

Any thoughts on how to do this easily?
Dec 14, 2013 at 3:53 AM
Worth a shot: cast each field to dynamic, then get Value and see if you get something.
Dec 14, 2013 at 4:22 AM
That did the trick. Earlier I had tried casting Fields to a List<dynamic> but that failed, and I hadn't considered your suggestion. Thanks!