This has been driving me daft and i thought it would be quite easy. I am trying to do a select and a number of WHERE's...something like this:
foreach(var page in currentNode.Children.Random(1).Where("Visible").Where("featuredRecipe").Where(MULTINODETREEPICKER CONTAINS VALUE))
As you can see (dont even know if this is possible!) but i am trying to filter this so it only returns matches where the multi-node tree picker values contain "x" (querystring)
Okay, try to do Where("myPickerProperty.ToString().Contains(\"bla\") instead. There is some upcasting going on, so the picker likely doesn't get represented as a string.
Related to this, why would the following return nodes containing "2742", but the latter not return anything?
//works
foreach (var post in selection.Where("postCategories.ToString().Contains(\"2742\")").OrderBy("BlogPostDate desc").Take(20))
// doesn't
string categoryId = "2742"; foreach (var post in selection.Where("postCategories.ToString().Contains(\"@categoryId\")").OrderBy("BlogPostDate desc").Take(20))
Razor Where Contains
Hi All,
This has been driving me daft and i thought it would be quite easy. I am trying to do a select and a number of WHERE's...something like this:
foreach(var page in currentNode.Children.Random(1).Where("Visible").Where("featuredRecipe").Where(MULTINODETREEPICKER CONTAINS VALUE))
As you can see (dont even know if this is possible!) but i am trying to filter this so it only returns matches where the multi-node tree picker values contain "x" (querystring)
Any info... muchly appreciated!
Thanks
Kenny
I am not sure if this works, but have you tried:
Of course you can always fall back on doing it inside the foreach:
Hi Sebasiaan,
Thanks for the reply - the first way looks correct and if i use this method using say bodyText this seems to work fine.
e.g. foreach(var page in currentNode.Children.Random(1).Where("Visible").Where("featuredRecipe").Where("bodyText.Contains(\"bla\")"))
However, it does not seem to want to play when I am referencing a multi node tree picker...
I would probably need it to work the first way. If not i can always go back and try it in XSLT!
Thanks -
Kenny
Oh no, not XSLT! ;-)
Okay, try to do Where("myPickerProperty.ToString().Contains(\"bla\") instead. There is some upcasting going on, so the picker likely doesn't get represented as a string.
:(
I know, i am quite enjoying Razor but this really is driving me insane!
Still no luck - would it be something like myPickerProperty.Values.ToString().Contains(\"bla\")
???
Got it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! it was InnerText that was required!
foreach(var page in currentNode.Children.Where("Visible").Where("pageFilters.InnerText.ToString().Contains(\"1248\")").Random(1))
Thanks a lot Seb - this is the reason i love this community! Together we can achieve :)
Kenny
Awesome! To be honest, it shouldn't be this hard, but I'm glad you got it to work.
Thanks again :)
Hi,
Related to this, why would the following return nodes containing "2742", but the latter not return anything?
//works
// doesn't
Thanks for your help,
Amir
Hi,
This is a pretty old question but maybe is useful for someone else.
@Amir - The solution to your problem is as follow:
The key point is to add + before and after your variable.
Cheers,
is working on a reply...