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
Hi,
Does anyone know why this OrderBy statement in my Razor script produces an error?:
@using umbraco.MacroEngines@inherits umbraco.MacroEngines.DynamicNodeContext@{ var year = DateTime.Now.Year; DynamicNode yearfolder = @Model.AncestorOrSelf().Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First(); DynamicNodeList publications = yearfolder.GetChildrenAsList;}<div class="C00_Clean container"> <div class="widget-title">Latest publications</div> <div id="twitter" class="widget widget-twitter"> @foreach (DynamicNode publication in publications.OrderBy("createDate desc")) { publication.Name; }</div> </div>
The intellisense message in VS when I hover over the OrderBy statement is: "The type arguments can not be inferred from the usage. Try specifying the type arguments explicitly"
How can I solve this?
Thanks for your help,Anthony
I should more trust VS intellisense :) this works:
@foreach (DynamicNode publication in publications.OrderBy<DynamicNode>("createDate desc"))
{
@publication.Name;
}
Hi Anthony.
try this :
dynamic publications = @Model.AncestorOrSelf().Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First().Children;
DynamicNodeList sortPublications = publications.OrderBy("createDate desc");
@foreach (DynamicNode publication in sortPublications ) { publication.Name; }
Or :
DynamicNodeList publications = @Model.AncestorOrSelf().Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First().Children.OrderBy("createDate desc");
@foreach (DynamicNode publication in publications ) { publication.Name; }
Hope that help. Cheers
Just now saw your second message.
:)
Hi gilad, no problem, I'm glad I could solve a Razor problem myself for once. Maybe your code will help someone else struggling with Razor.
greetings,
Anthony
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
OrderBy not working in my Razor script
Hi,
Does anyone know why this OrderBy statement in my Razor script produces an error?:
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var year = DateTime.Now.Year;
DynamicNode yearfolder = @Model.AncestorOrSelf().Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First();
DynamicNodeList publications = yearfolder.GetChildrenAsList;
}
<div class="C00_Clean container">
<div class="widget-title">Latest publications</div>
<div id="twitter" class="widget widget-twitter">
@foreach (DynamicNode publication in publications.OrderBy("createDate desc"))
{
publication.Name;
}
</div>
</div>
The intellisense message in VS when I hover over the OrderBy statement is: "The type arguments can not be inferred from the usage. Try specifying the type arguments explicitly"
How can I solve this?
Thanks for your help,
Anthony
I should more trust VS intellisense :) this works:
@foreach (DynamicNode publication in publications.OrderBy<DynamicNode>("createDate desc"))
{
@publication.Name;
}
Hi Anthony.
try this :
dynamic publications = @Model.AncestorOrSelf().Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First().Children;
DynamicNodeList sortPublications = publications.OrderBy("createDate desc");
@foreach (DynamicNode publication in sortPublications )
{
publication.Name;
}
Or :
DynamicNodeList publications = @Model.AncestorOrSelf().Descendants("PublicationFolderYear").Where("Name == \"" + year + "\"").First().Children.OrderBy("createDate desc");
@foreach (DynamicNode publication in publications )
{
publication.Name;
}
Hope that help. Cheers
Just now saw your second message.
:)
Hi gilad, no problem, I'm glad I could solve a Razor problem myself for once. Maybe your code will help someone else struggling with Razor.
greetings,
Anthony
is working on a reply...