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.
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.
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:
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
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?
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
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.