I have a "list" of nodes and I want to filter them for a specific property value. The property value can contain the searchterm or it can be equal. I look for something that is similiar to a sql statement, where you would use the LIKE-Syntax.
SELECT field FROM table LIKE '%@searchterm%'
At the moment my razor syntax looks like
nodes.Where("contentHeadline=='@searchTearm'");
And I would like to filter the nodes like this
nodes.Where("contentHeadline LIKE '%@searchTearm%'");
Can someone help me, please? How can I achieve this with razor syntax?
but I cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Ok, I think we are on the right track. Thank you very much!! But first, I have to fix the subsequent faults. I cant access the method "Count()" for example or the properties directly. I think I get the properties from the method "getPropertyValue" ?
Filter noderesults
Hi,
I have a "list" of nodes and I want to filter them for a specific property value. The property value can contain the searchterm or it can be equal. I look for something that is similiar to a sql statement, where you would use the LIKE-Syntax.
At the moment my razor syntax looks like
And I would like to filter the nodes like this
Can someone help me, please? How can I achieve this with razor syntax?
Thanks and regards,
Nadine
UPDATE:
I tried to use a Lambda-Syntax like this
but I cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Hi Nadine,
can you post the code where you assign the property nodes? If you are using dynamics then I would suggest moving to strongly types then you can use:
Like in your update.
Hope this helps.
/Michaël
Hi Nadine
Let's rewrite all code to the strongly typed, then your code with linq where query will be working.
/Alex
Dear all,
thank you for your fast reply.
I select the nodes like this
How can I convert it to the strongly typed? I am on a UmbracoTemplatePage.
Thanks
/Nadine
Hi Nadine
What type of property editor is OverviewPage? Is it some type of Node picker?
/Alex
If it's multinode tree picker, then the code will look like:
The overviewpage is the first Children of the currentPage with a specific documenttype , it is not a property.
Then this code:
So you need child nodes of first child?
Yes, exactly.
But this needs to be more specific
This selections " Umbraco.AssignedContentItem.Children" must relates to the DocumentType "Fragen"
At the Moment my selector for the overviewpage is
This is more specific - first child and docTypeAlias equals "Fragen"
Ok, I think we are on the right track. Thank you very much!! But first, I have to fix the subsequent faults. I cant access the method "Count()" for example or the properties directly. I think I get the properties from the method "getPropertyValue" ?
Nadine, you also can use MoldesBuilder for easier access to properties.
You have to cast the node to ModelsBuilder type, for example you can get typed fragen node like that:
For this statement, I get the error: 'System.InvalidOperationException: Sequence contains no elements'
I looked at the Template for the DocumentTypeAlias , it is "Fragen", so it should be ok.
Nadine, did you look at a template? DocumentTypeAlias it's in the document type settings.
You are right :) In the Document Type Settings it is lowercase written. Thanks again :)
Just one more Question:
How can I check the number of elements from this statement
I hope that's it. :)
Hi Nadine,
you can use
nodes.Count()
to get the number of elements returned by your query.Hope this helps.
/Michaël
Hi Nadine,
Just use .Count() method, like that:
Sorry and thank you, guys. It seems not to work, because I overwrote an existing variable with a dynamic data type.
But now I get the correct result. AWESOME :) You saved my day! Thanks!
You are welcome, Nadine, have a great day too.
It's nice to be involved in process rewriting dynamic types code to strongly typed :))
is working on a reply...