I might be wrong but I think given this is Umbraco v4 we are dealing with a Razor Macro using DynamicNode (stored in MacroScripts) rather than a View/Partial View/Macro Partial View using IPublishedContent (stored in Views). Perhaps Daniel could confirm?
Actually there is a potential problem with this, you would need to select the first "LunchPage" which matches the lunchCity (and check it's not null), e.g.
var root = Model.AncestorOrSelf("FrontPage").Descendants("LunchPage").Where("lunchCity == @0", "Esbjerg").FirstOrDefault();
if (root != null)
{
var sub = root.Descendants("LunchDay").Where("lunchDate == DateTime.Now.Date");
}
Razor where acting weird
Hi, I have a small problem. I am updating a website to make it possible having a lunchplan for two different locations. Umbraco v4.11.4
Before it looked like this:
Now it looks like this and it is not working:
There is a dropdown with the city names on the LunchPage and it is choosen.
The structure is like this: LunchPage - Esbjerg LunchWeek LunchDay
LunchPage - Roskilde LunchWeek LunchDay
I cannot see any error, but there must be one.
Thank you for the help. /Daniel
Hi Daniel,
Generally looks fine, if you remove the .Where do you get a collection ok? E.g
var root = Model.AncestorOrSelf("FrontPage").Descendants("LunchDay");
Also, maybe try:
Jeavon
Dammit! I switched the two. It is the lunchCity that is ruining everything. It should look like this:
Before it looked like this:
Now it looks like this and it is not working:
Ah ok, try this then
Daniel Larsen and Jeavon this razor feels odd. i could be wrong. Are you in c# or razor?
IPublishedContent root = Model.AncestorOrSef("string parameter").Descendants("string parameter").Where(x=>x.GetPropertyValue("lunchCity).toString() == "Esbjetg").Descendants("LunchDay").Where(x=>x.GetPropertyValue("lunchDate").toString() == DateTime.Now.Date);
It will be more like that. Needs some tweaking, just done it off the top of my head rather than in visual studio. Hope this helps.
Hi Charles,
I might be wrong but I think given this is Umbraco v4 we are dealing with a Razor Macro using DynamicNode (stored in MacroScripts) rather than a View/Partial View/Macro Partial View using IPublishedContent (stored in Views). Perhaps Daniel could confirm?
Jeavon
Hi, I have not had time to test the solution yet, but yes, it is v4 and I am using macro scripts.
Thanks :-)
Hi Daniel,
Actually there is a potential problem with this, you would need to select the first "LunchPage" which matches the lunchCity (and check it's not null), e.g.
Jeavon
got you, thanks Jeavon :)
is working on a reply...