Converting a blocklist
# help-with-umbraco
t
Hi I'm using a blocklist which has an element containing a few properties. I would like to retrieve one of these fields as a list. I've managed to get the data like Var data = rootSource.AllCustomers; The type is down as blocklistItem. Rootsource is the UmbracoContext getting the data from my tree in Umbraco. When I try var custCode = data.Select(z=> z.Content.CustCode) I get an error that is not found. CustCode is the name of property in the element that I'm trying to retrieve. In debug mode I see all the values I'm after but I can't retrieve them in this way, what have I missed?
r
The
BlockListItem
type doesn't know what the underlying content model is, so you'll probably need to cast it. Maybe something like (with null checking)
Copy code
csharp
var data = rootSource.AllCustomers as List<BlockListItem<YourContentModel>>
or even reselect the list first
Copy code
csharp
var custCodeTyped = data.Select(x => x as BlockListItem<YourContentModel>);
var custCode = custCodeTyped.Select(x => x.Content.CustCode) //Should now work
4 Views