Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Larsen 116 posts 381 karma points
    Jan 07, 2014 @ 14:42
    Daniel Larsen
    0

    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:

    var root = Model.AncestorOrSelf("FrontPage").Descendants("LunchPage").Where("lunchCity == \"Esbjerg\"").Descendants("LunchDay").Where("lunchDate == DateTime.Now.Date");
    

    Now it looks like this and it is not working:

    var root = Model.AncestorOrSelf("FrontPage").Descendants("LunchDay").Where("lunchDate == DateTime.Now.Date");
    

    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

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 07, 2014 @ 18:47
    Jeavon Leopold
    0

    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:

    var root = Model.AncestorOrSelf("FrontPage").Descendants("LunchDay").Where("lunchDate == @0", DateTime.Now.Date);
    

    Jeavon

  • Daniel Larsen 116 posts 381 karma points
    Jan 07, 2014 @ 19:19
    Daniel Larsen
    0

    Dammit! I switched the two. It is the lunchCity that is ruining everything. It should look like this:

    Before it looked like this:

    var root =Model.AncestorOrSelf("FrontPage").Descendants("LunchDay").Where("lunchDate == DateTime.Now.Date");

    Now it looks like this and it is not working:

    var root =Model.AncestorOrSelf("FrontPage").Descendants("LunchPage").Where("lunchCity == \"Esbjerg\"").Descendants("LunchDay").Where("lunchDate == DateTime.Now.Date");
  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 07, 2014 @ 19:51
    Jeavon Leopold
    0

    Ah ok, try this then

    var root =Model.AncestorOrSelf("FrontPage").Descendants("LunchPage").Where("lunchCity == @0", "Esbjerg").Descendants("LunchDay").Where("lunchDate == DateTime.Now.Date");
    
  • Charles Afford 1163 posts 1709 karma points
    Jan 07, 2014 @ 22:58
    Charles Afford
    0

    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.

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 07, 2014 @ 23:57
    Jeavon Leopold
    0

    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

  • Daniel Larsen 116 posts 381 karma points
    Jan 08, 2014 @ 22:45
    Daniel Larsen
    0

    Hi, I have not had time to test the solution yet, but yes, it is v4 and I am using macro scripts.

    Thanks :-)

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jan 10, 2014 @ 11:24
    Jeavon Leopold
    0

    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.

    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");
    }
    

    Jeavon

  • Charles Afford 1163 posts 1709 karma points
    Jan 13, 2014 @ 21:21
    Charles Afford
    0

    got you, thanks Jeavon :)

Please Sign in or register to post replies

Write your reply to:

Draft