I'd like to add to the 'Home' page of a footballwebsite the football matchs from all 10 teams which take place the next 7 days.
All the matchs are already entered. I have one item 'matchs' in the website tree which has 10 children (the 10 teams). Each children item has several children with document type 'match' and a property 'date'.
How do I select now ALL matchs which take place the next 7 days?
Are you using Webforms templates (.master) with Razor macro's or Mvc View templates (.cshtml)?
For a Razor macro I think something like this:
var nextMatches = Model.XPath("//matches/teams/match").Where("date < DateTime.Now.AddDays(7)").OrderBy("date");
foreach (var match in nextMatches)
{
<p>@match.Name</p>
}
This assumes that your document types are named "matches", "teams" & "match" but you can update the XPath expression to match your document type aliases.
Query to select all matchs of the following week
Hello!
I'm quite new in Umbraco.
I'd like to add to the 'Home' page of a footballwebsite the football matchs from all 10 teams which take place the next 7 days.
All the matchs are already entered. I have one item 'matchs' in the website tree which has 10 children (the 10 teams). Each children item has several children with document type 'match' and a property 'date'.
How do I select now ALL matchs which take place the next 7 days?
Thanks,
Kristina
Hi Kristina,
Are you using Webforms templates (.master) with Razor macro's or Mvc View templates (.cshtml)?
For a Razor macro I think something like this:
This assumes that your document types are named "matches", "teams" & "match" but you can update the XPath expression to match your document type aliases.
If you are using Mvc, let me know.
Thanks,
Jeavon
Thanks for your reply but yes, I'm using MVC..
Ok, using the typed model:
Thank you. I tried it and got this error:
Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Hi Kristina,
Can you please post your complete code?
Thanks,
Jeavon
@{
var nextMatches = Model.Content.AncestorOrSelf(1).Descendants("Spiel").Where(x => x.GetPropertyValue<DateTime>("Datum") < DateTime.Now.AddDays(7)).OrderBy(x => x.GetPropertyValue<DateTime>("Datum"));
foreach (var match in nextMatches)
{
<p>match: @match.GetPropertyValue("Gegner")- @match.GetPropertyValue("Datum")</p>
}
}
I don't understand 'x.GetPropertyValue<DateTime>'
Can you post your entire view code, everything in the template?
is working on a reply...