Attempting to do a double sort in Razor involving two date fields. It seems I can sort by either of them independently, however whenever I have a date field with another field in the sort string, razor throws an error. I can sort by two non-date fields, but if either field is a date it throws the following error:
Error loading Razor Script Unable to cast object of type
'System.Func`2[umbraco.MacroEngines.DynamicNode,System.DateTime]' to
type 'System.Func`2[umbraco.MacroEngines.DynamicNode,System.Object]'.
Here are the scenarios:
.OrderBy("createDate desc") -> Single Date ordering = success .OrderBy("name, location desc") -> Two non-date field order = success .OrderBy("createDate, location desc") -> Two date or one date and one non-date = failure .OrderBy("location. createDate desc") -> Two date or one date and one non-date = failure
Before I submit this I wanted to confirm this was actually a bug and not just something I'm not understanding.
This is a known bug in 4.7 and is fixed in 4.7.1. You can download the latest nightly build and only use the umbraco.macroengines.dll, that should work fine, it's been very stable.
Date Error in Razor OrderBy?
Umbraco 4.7
Attempting to do a double sort in Razor involving two date fields. It seems I can sort by either of them independently, however whenever I have a date field with another field in the sort string, razor throws an error. I can sort by two non-date fields, but if either field is a date it throws the following error:
Error loading Razor Script
Unable to cast object of type 'System.Func`2[umbraco.MacroEngines.DynamicNode,System.DateTime]' to type 'System.Func`2[umbraco.MacroEngines.DynamicNode,System.Object]'.
Here are the scenarios:
.OrderBy("createDate desc") -> Single Date ordering = success
.OrderBy("name, location desc") -> Two non-date field order = success
.OrderBy("createDate, location desc") -> Two date or one date and one non-date = failure
.OrderBy("location. createDate desc") -> Two date or one date and one non-date = failure
Before I submit this I wanted to confirm this was actually a bug and not just something I'm not understanding.
Thanks.
--Chris
This is a known bug in 4.7 and is fixed in 4.7.1. You can download the latest nightly build and only use the umbraco.macroengines.dll, that should work fine, it's been very stable.
Good to know its been fixed. I'll probably do a work-round for now and wait until 4.7.1 has been released to keep the code bases managable on my end.
Thanks Sebastiaan.
--Chris
I know this is a really old post, but how do you sort ascending not desc?
Could it be, that the bug is 4.11.8 again or am I doing anything wrong?
Ditto on 4.11.8, similar issue here
is working on a reply...