Add "Where" filter to a multi node tree picker property
@Model.Children.Where("catCount = 1")
It is possible to add a Where filter to a property (catCount) like above. Suppose this catCount is a uComponentsmulti node tree picker property. How do we add a filter for that?
I think what you have to do is detect what information the property actually contains and then filter. In the case of a multi node tree picker, this will probably be a list of node ID's. So looking for a specific ID can probably be done with something like .Where("catCount.Contains(1)").
By the way, your example might not work because your filter should be "catCount == 1" I think.
It gives a node list like below for .ToXml(). ".Contains(1281)" filter doesn't work. It says "No applicable method 'Contains' exists in type 'String'". Also catCount == 1281 or catCount.nodeId doesn't return any value. Seems we need to do some XML processing.
There is mention that you can parse XML with a dot notation:
---- Start quote
XML Properties
If you have a field which contains valid XML, and wasn't generated from an RTE, DynamicNode will detect this and allow you to access it with . notation If there's more than one node with the same name, you'll need to use [] indexing to access the element you want
Here's an example: @Model.xmlProperty.Catalog.Books[1].Genre
Warning: the property access is case sensitive. Make sure you check your case. The root node is removed, so omit that, and remember to check for indexing if you have multiple nodes that might be returned.
If the XML function is kicking in, your root node may need to be excluded - check umbracoSettings.config for an override of document element types that shouldn't be converted
--- End quote
So, you apparently should be able to access your nodeID's as a list with something like this: @Model.catCount.MultiNodePicker.NodeIds
Add "Where" filter to a multi node tree picker property
@Model.Children.Where("catCount = 1")
It is possible to add a Where filter to a property (catCount) like above. Suppose this catCount is a uComponents multi node tree picker property. How do we add a filter for that?
Thanks.
Hi Dorian,
I think what you have to do is detect what information the property actually contains and then filter. In the case of a multi node tree picker, this will probably be a list of node ID's. So looking for a specific ID can probably be done with something like .Where("catCount.Contains(1)").
By the way, your example might not work because your filter should be "catCount == 1" I think.
Cheers,
Michael.
Hi Michael,
It gives a node list like below for .ToXml(). ".Contains(1281)" filter doesn't work. It says "No applicable method 'Contains' exists in type 'String'". Also catCount == 1281 or catCount.nodeId doesn't return any value. Seems we need to do some XML processing.
<MultiNodePicker type="test"><nodeId>1281</nodeId><nodeId>1277</nodeId><nodeId>1278</nodeId><nodeId>1274</nodeId></MultiNodePicker>
Thanks.
Hi Dorian,
Then maybe you can have a look at this link : http://umbraco.com/follow-us/blog-archive/2011/2/28/umbraco-razor-feature-walkthrough-%E2%80%93-part-3
There is mention that you can parse XML with a dot notation:
---- Start quote
XML Properties
If you have a field which contains valid XML, and wasn't generated from an RTE, DynamicNode will detect this and allow you to
access it with . notation
If there's more than one node with the same name, you'll need to use [] indexing to access the element you want
Here's an example:
@Model.xmlProperty.Catalog.Books[1].Genre
Warning: the property access is case sensitive. Make sure you check your case.
The root node is removed, so omit that, and remember to check for indexing if you have multiple nodes that might be returned.
If the XML function is kicking in, your root node may need to be excluded - check umbracoSettings.config for an override of document element types that shouldn't be converted
--- End quote
So, you apparently should be able to access your nodeID's as a list with something like this: @Model.catCount.MultiNodePicker.NodeIds
And you might also want to have a look at this package http://our.umbraco.org/projects/developer-tools/cultiv-razor-examples which gives razor examples about using razor witj all uComponents data types.
Hope this can help you further.
Cheers,
Michael
is working on a reply...