Simple conversion of Block List content items to List
I'm busy trying to future proof a my current website project by converting all my Nested Content properties to Block Lists.
In the deep dive documentation this is the suggested way to get the content from the Block List Content Items.
@foreach(var blockItem in Model.MyProperty) {
var blockItemContent = (ContentModels.MyElementTypeAlias)blockItem.Content;
<h2>@blockItemContent.MyBlockProperty</h2>
}
With Nested Content I could easily convert the property values into an IEnumerable list of ContentModels.MyElementTypeAlias.
If all I'm interested in is the Block List Item Content properties from each item in the Block List Model then is there a smart way to extract those straight into an IEnumerable list of ContentModels.MyElementTypeAlias?
var items = from blockListItems in this.Value<Umbraco.Core.Models.Blocks.BlockListModel>("myBlockList") select blockListItems.Content as ContentModels.MyElementTypeAlias;
Simple conversion of Block List content items to List
I'm busy trying to future proof a my current website project by converting all my Nested Content properties to Block Lists.
In the deep dive documentation this is the suggested way to get the content from the Block List Content Items.
With Nested Content I could easily convert the property values into an IEnumerable list of ContentModels.MyElementTypeAlias.
If all I'm interested in is the Block List Item Content properties from each item in the Block List Model then is there a smart way to extract those straight into an IEnumerable list of ContentModels.MyElementTypeAlias?
Thanks,
Matt
This is what I was looking for:
Is this what you wan't?
Yes, that's it.
Thanks Casper.
Thank you so much for putting this here as I was also looking for the same query.
SectionBlockItem which is the class to map
is working on a reply...