Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Apr 25, 2012 @ 09:51
    Anthony Candaele
    0

    problem with Razor .Where clause

    Hi,

    I'm trying to implement filtering on a documentype 'Member'. This documenttype has a property 'memberCategory' of datatype 'dropdownlist'.

    The xml looks like this:

     

    <Member id="1071" parentID="1065" level="3" writerID="0" creatorID="0" nodeType="1063" template="1069" sortOrder="3" createDate="2012-04-24T10:36:22" updateDate="2012-04-24T11:04:58" nodeName="John Doe" urlName="john-doe" writerName="admin" creatorName="admin" path="-1,1051,1065,1071" isDoc="">

            <memberFirstName>John</memberFirstName>

            <memberLastName>Doe</memberLastName>

            <memberEmail>[email protected]</memberEmail>

            <memberPhone>some phonenumber</memberPhone>

            <memberFax>some faxnumber</memberFax>

            <memberAddress><![CDATA[Ghent University, Department of Razor Sciences

    Some street, some postal number, some city, some country]]></memberAddress>

            <memberVisitingHours><![CDATA[]]></memberVisitingHours>

            <memberBio><![CDATA[

    <p>some bio information</p>

    ]]></memberBio>

            <memberPublications />

            <memberCategory><![CDATA[Professor]]></memberCategory>

            <pageTitle>Gino Verleye</pageTitle>

            <pageDescription><![CDATA[Details Prof. Dr. Gino Verleye]]></pageDescription>

            <umbracoNaviHide>0</umbracoNaviHide>

          </Member>

    I want to render all the members that have for the property 'memberCategory' the value 'Professor'

    My Razor-script looks like this:

    @foreach (var item in @Model.Member.Where("memberCategory == Professor"))
        {
            
             <h2>Professor</h2>
             <ul class="nav">
                <li><href="@item.Url">@item.Name</a></li>
             </ul>         
    }

     

    However, this doesn't work

    I'm still pretty new to Razor in Umbraco, can someone help me out with this?

    Thanks,
    Anthony

  • gilad 185 posts 425 karma points
    Apr 25, 2012 @ 09:56
    gilad
    2

    Hi,

    Try this :

    @foreach (var item in @Model.Children.Where("memberCategory == \"Professor\""))
        {
            
             <h2>Professor</h2>
             <ul class="nav">
                <li><href="@item.Url">@item.Name</a></li>
             </ul>         

    } 

  • Anthony Candaele 1197 posts 2049 karma points
    Apr 25, 2012 @ 09:59
    Anthony Candaele
    0

    Hi gilad,

    You made my day, this works :)

    Thanks a lot for your help,

    Anthony

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Apr 25, 2012 @ 10:28
    Jeroen Breuer
    0

    Beware that .Where might have some performance issues in Razor: http://our.umbraco.org/forum/developers/razor/28479-Razor-menu-performance-(v4)

    Jeroen

  • Tony Kiernan 278 posts 341 karma points
    Jun 26, 2012 @ 13:50
    Tony Kiernan
    0

    I'm having an issue with spaces in my where clause.  For example:

    @Model.Children.Where("memberCategory ==\"Professor\"");

    Happy

    @Model.Children.Where("memberCategory ==\"Tenured Professor\"");

    Nothing. Is there something in the way where clauses handle spaces?

    (The values are not mine to change, sadly)

  • Douglas Ludlow 210 posts 366 karma points
    Jun 26, 2012 @ 15:51
    Douglas Ludlow
    0

    Try:

    var collection = Model.Children.Where("memberCategory == @0", "Tenured Professor");
Please Sign in or register to post replies

Write your reply to:

Draft