Copied to clipboard

Flag this post as spam?

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


  • Tom 713 posts 954 karma points
    Jul 05, 2011 @ 00:02
    Tom
    0

    Razor Where Clauses?!

    Hi i was just wondering the rules when it comes to where clauses?

    it appears you can't Where("something == true && somethingelse == "somestring")

    i.e. var items = node.Children.Where("Visible && !showInFooter").Where("Level <maxLevelForSitemap", values);

    is that the case? or am i just setting up my clauses incorrectly? or do you need a separate where statement for each item you're filtering on?

    do I have to check if the showInFooter property exists before I can use it?!

    Cheers,

    Tom

  • Tom 713 posts 954 karma points
    Jul 05, 2011 @ 00:08
    Tom
    0
    var items = node.Children.Where("Visible").Where("Level <= maxLevelForSitemap", values).Where(!HasProperty("showInFooter") || (HasProperty("showInFooter") && !showInFooter));
    i'VE ALSO TRIED THIS.. TO NO AVAIL...
    Are there any common examples out there for filtering based on property values in where clauses? there just seems to be a lack of grass roots examples out there for very common xslt type functions converted to razor..
  • RGoodSW 5 posts 25 karma points
    Jun 25, 2012 @ 18:29
    RGoodSW
    0

    I found that the less than symbol (<) in the .Where caused the script to fail.

    What's the trick to posting colorized syntax?  I'd be happy to post a sample of what I have working.

    Regards,
    Bob G.

  • Carlos 338 posts 472 karma points
    Jun 25, 2012 @ 22:26
    Carlos
    0

    @RGoodSW

    Colorized syntax should be fine if you copy it in from the Umbraco editor and from the droplist here in the comments section tha says "Paragraph" there should be an option for "preformatted."  Post you code in that.

     

  • RGoodSW 5 posts 25 karma points
    Jun 26, 2012 @ 02:21
    RGoodSW
    0
    <umbraco:Macro  runat="server" language="cshtml">
      @using System;
      var now = DateTime.Now;
      <h3>Rehearsals</h3>
      <table>
        <tbody>
          <tr><th class="rehgrid">Date</th><th class="rehgrid">Time</th><th class="rehgrid">Location</th><th class="rehgrid">Comments</th></tr>
      @foreach (var rehearsal in @Model.Descendants("Rehearsal").Where("!finished").OrderBy("startDatetime"))
      {
        if (@rehearsal.HasProperty("startDatetime"))
        {
          var url = rehearsal.GetProperty("Url");
          <tr><td class="rehgrid"><a href="@url">@rehearsal.startDatetime.ToString("ddd  yyyy-MM-dd")</a></td>
            <td class="rehgrid">@rehearsal.startDatetime.ToString("h:mm tt")&nbsp;-&nbsp;@rehearsal.endDatetime.ToString("h:mm tt")</td>
            <td class="rehgrid">@rehearsal.location</td>
            <td class="rehgrid">@rehearsal.comments</td></tr>
         }
        else
        {
          <tr><td>nothing</td><td></td><td></td><td></td></tr>
        }
      }
      </tbody>
      </table>
    </umbraco:Macro>

    ---

    This is from a test page that successfully shows current and future rehearsals in a table.  There are a few extraneous lines in there.  What I had wanted to do was to compare the value endDatetime with "now", but the greater than and less than symbols caused the macro to fail to load.

    Hope this helps.

    Regards,
    Bob G.

Please Sign in or register to post replies

Write your reply to:

Draft