TigerMan
02/19/2025, 12:27 PMJonathon Cove
02/19/2025, 1:17 PMvar custs = page.Customers.Select(x=> x.Content as Customer).OrderBy(c => c.Name)
That'll also give you a list of Customers, for use when you need themTigerMan
02/19/2025, 1:46 PMJemayn
02/19/2025, 1:48 PMCustomers?TigerMan
02/19/2025, 1:51 PMJemayn
02/19/2025, 1:53 PMJemayn
02/19/2025, 2:01 PMx.Content inside your select is of the type IPublishedElement, and Customer inherits from PublishedElementModel then it should be able to cast it.
If it cannot then you may have other blocks within the blocklist that are not of the type CustomerJemayn
02/19/2025, 2:04 PMcsharp
var custs = page.Customers.Select(x=> x.Content).OfType<Customer>().OrderBy(c => c.Name);
To get around the unsafe cast issueTigerMan
02/19/2025, 2:09 PMJemayn
02/19/2025, 2:20 PMTigerMan
02/19/2025, 2:23 PMJemayn
02/19/2025, 2:25 PMcsharp
var customers = page.Customers.Select(x=> x.Content).OfType<Customer>().OrderBy(c => c.Name);
Then customers are a list of Customers ordered by name. So you probably want to change the return type from BlockListModel to IEnumerable and then change the callers of the method to this instead