Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Nov 26, 2013 @ 17:54
    Dan
    0

    Get children where child MNTP property is equal to querystring value

    Hi,

    I have a (v6.1.6 MVC) site with a page of articles which need to be filtered by location. The location is being set through a querystring variable (locationId). The filter only needs to apply if the querystring variable is set - if not all articles will be returned.

    I have a property on the article document type called 'location' which is a multi node tree picker (max. 1 item), which stores the same location ids as those that will be passed in via the querystring.

    The code I have so far is:

    string locationId = Request.QueryString["locationId"];
    
    var listings = Model.DescendantsOrSelf("ListingItem").Where("Visible");
    
    if(!String.IsNullOrEmpty(locationId)){
        @* Here the listings need to be refined or re-selected to pick only those where the location matches.  So something like this: *@
        listings = listings.Where("location = " + locationId);
    }
    

    I think the most complex thing here is that the location is saved as a multi node tree picker value (CSV) so isn't a string.

    Can anyone suggest how to get this working?

    Thanks

  • Charles Afford 1163 posts 1709 karma points
    Nov 26, 2013 @ 21:00
    Charles Afford
    0

    Ok well you can get the query string from HttpRequest.QueryString

    You can get the csv and split on the ' , '

    Then you just need to see if there is a match?

    Charlie :).

    If the query string does not contain your stuff or is empty then just render all the values?

  • Dan 1288 posts 3921 karma points c-trib
    Nov 29, 2013 @ 14:55
    Dan
    0

    Thanks Charlie.

    That's it in a nutshell. What I could do is take the listings variable and loop through it, and run a check (split/compare) on each iteration to see if it matches, and potentially store the results to a new variable for working with. That should be pretty simple. But what I thought would be neater would be if the appropriate nodes were selected to begin with - so essentially the matching is done in the selector. This is the part I'm struggling with.

    Any ideas how to do this?

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft