var items = CurrentPage.GetPropertyValue<IEnumerable<IPublishedContent>>("afh").OrderBy(x => x.GetPropertyValue<DateTime>("startdato"));
Gives me the error
Compiler Error Message: CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
You're on the 2016 "i owe you beer at codegarden" list.
That's the one thing i hate most about razor. The possibillity of doing things more than one way, and the two ways being 99% similar, but then not really... The hours i've spent...
With Razor, when I switched over from using XSLT, I got confused with the dynamic/typed approaches. I ended up ignoring all the dynamic stuff and stuck with typed-objects.
Mixing both dynamic & typed approaches caused me a world of pain ;-)
I would like to sort the nested content from another page, i use the following code and it gives error ( CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type).
var timelineNode= Umbraco.Content(CurrentPage.AncestorOrSelf(1).Descendants("timeline").First().Id);
var datesList = timelineNode.GetPropertyValue<IEnumerable<IPublishedContent>>("dates").OrderByDescending(x => x.GetPropertyValue<DateTime>("date"));
timeline is doc type, dates is nested content data type property.
If i test without ordering it works.
var timelineNode= Umbraco.Content(CurrentPage.AncestorOrSelf(1).Descendants("timeline").First().Id);
var datesList = timelineNode.GetPropertyValue<IEnumerable<IPublishedContent>>("dates");
How to sort items?
Im trying to sort the items rendered by nested content like:
}
But i get the errror
How do i correctly sort the items?
Hi Claus,
I'm not familiar with the string syntax in
.OrderBy("startdato")
, I guess this is an Umbraco extension method? (I typically use lambda syntax)I guess this might be similar to the issue you had previously, namespace references are missing?
Try adding...
...to the top of your Razor partial?
Hope that helps?
Cheers,
- Lee
That didn't do the trick, but maybe you could show a snippet on how to.
"startdato" is a date picker. I want to sort by the date picker and then take 1. So im looking for the right way to do:
You could try...
Cheers,
- Lee
Gives me the error
I wonder if ill ever learn razor :|
Ah, I think it's the
CurrentPage
being dynamic. Try swapping it out withModel.Content
, see if that works?Bingo!
You're on the 2016 "i owe you beer at codegarden" list.
That's the one thing i hate most about razor. The possibillity of doing things more than one way, and the two ways being 99% similar, but then not really... The hours i've spent...
You're welcome! :-)
With Razor, when I switched over from using XSLT, I got confused with the dynamic/typed approaches. I ended up ignoring all the dynamic stuff and stuck with typed-objects.
Mixing both dynamic & typed approaches caused me a world of pain ;-)
Cheers,
- Lee
Thanks for the tips.
What wolud be the syntax if we needed to change sort order by date?
Edit:
OrderBy should be switched by OrderByDescending to change the sort direction.
Thank you ;)
I would like to sort the nested content from another page, i use the following code and it gives error ( CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type).
timeline is doc type, dates is nested content data type property.
If i test without ordering it works.
Any ideas?
is working on a reply...