Sitecore sort children by __Created field -


i have sitecore 6.6 solution running mvc , razor. have following line;

@html.raw(sitecore.context.database.getitem(mylist.children.lastordefault()["myfield1"]).fields["myfield2"]) 

the above works fine, except order sorts in. need latest item based on __created field. lastordefault seems take last item in tree, not correspond actual latest created item.

can done in 1 line above?

how this:

mylist.getchildren() .orderby(x => x[sitecore.fieldids.created]) .reverse() .lastordefault() 

i guess work too:

mylist.getchildren() .orderby(x => x.statistics.created) .reverse() .lastordefault() 

keep in mind though first children retrieved , sorting happen. if have lot of children slow.

one general note, shouldn't in view really. you're putting logic in there. model should provide item need (last created).


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -