Craig100
07/15/2024, 8:17 PMvar listItems = Model.Content.ItemsToList.Children.Take(displayNum);
If it's a category list then it will have a "listOrderIndexNumber" field. As I want to output to the page in the correct order, after checking listItems is CategoryList I then try to output the CategoryPages in order like so:-
@foreach (CategoryPage item in listItems.OrderBy(x => x.GetProperty("listOrderIndexNumber"))) {
........
}
However during the processing of the foreach I get "ArgumentException: At least one object must implement IComparable."
I've tried various things like taking off the Take(displayNum), rerunning the collection with a different var after checking for CategoryList, but I get the same error all the time. I thought this would be simple, just order it by value, but there's something stopping me and I can't work out what it is. Googling hadn't helped.
There's a separate foreach for articleLists. I'm using one view for two, very similar purposes.
If anyone has any advice I'd love to hear it.
Thanks.Jemayn
07/15/2024, 8:29 PMIPublishedProperty?
as far as I can see.
Which it doesn't know how to compare several items of to order them.
You probably want to just get the value of the property cast to an int (I assume its a number?)
If I understand your code right then it should work with this:
csharp
foreach (CategoryPage item in listItems.OrderBy(x => x.Value<int>("listOrderIndexNumber")))
{
........
}
Craig100
07/15/2024, 11:15 PM