Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Using v6.1.2. I have created a blog and initially set them to be ordered by the node's createDate. In order to allow posts to be back-dated, a date-picker property, "datePublished" has been added to the doc type. Now, I'd like to order the posts based on datePublished first, then by createDate. Some of the example out there don't seem to be working. For example, using
dynamic posts = CurrentPage.Descendants("BlogPost").OrderBy("datePublished").And().OrderBy("createDate");
gives me the "Object reference not set to an instance of an object" error. OrderBy("datePublished", "createDate") didn't seem to work either.
Any suggestions? Thanks in advance for the help!
Did you try .OrderBy("datePublished, createDate")?
That syntax worked with DynamicNode but I've not tried it with dynamic Mvc (CurrentPage) so I'm not sure if its supported or not, if not then you should be able to use the ThenBy method with a typed object, something like
dynamic posts = Model.Content.Descendants("BlogPost").OrderBy(x => x.GetPropertyValue<DateTime>("datePublished")).ThenBy(x => x.CreateDate);
The second option is what I needed. Thank you!
Cool, I just amended a tiny typo above x.createDate should be x.CreateDate
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted