I have a directory of companies, which have 2 properties which are got from multinode tree pickers, Country and Activity. The contents of these are displayed as a list of checkboxes, and I need to be able to filter the directory according to what is checked.
I am having difficulty getting my head around this. Code is as follows - (with lots of things like styling and accordions and pagination stripped out so there might be tags and brackets missing - the page does work as is without filtering)
I have 2 lists which get the parameters coming in and then combine to one list of what needs to be filtered against. I just don't know how to query the items in showItems helper function to only show these companies.
ETA - Should I be able to write something like:
var items = node.Children.Where(x => (x.IsDocumentType(Rnm_StakeholderCompany.ModelTypeAlias)) && x.IsVisible() && (x.GetPropertyValue<IEnumerable<String>>("Country").Contains("1493")));
I'm getting "Exception Details: System.ArgumentNullException: Value cannot be null. "on this line
(using uskinned Source theme if that makes a difference)
I saw your example and others where people tried to make a string or an array of the items and check in there but could not get it to work in Umbraco 8.
The solution was to check the multinodepicker directly but because it may be empty sometimes and can not match an ID it through either an object error or value null error.
Checking to ensure not null first in a where then running through works well.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Models;
using Umbraco.Web;
namespace MySite.App_Code.USNHelpers
{
public static class MyHelpers
{
public static IEnumerable<IPublishedContent> AndIsLinkedToCountry(this IEnumerable<IPublishedContent> content, List<int> countryIds)
{
foreach (IPublishedContent c in content)
{
foreach (IPublishedContent country in c.GetPropertyValue<IEnumerable<IPublishedContent>>("Country"))
{
if (countryIds.Contains(country.Id))
{
yield return c;
}
}
}
}
}
}
in a file called App_Code/MyHelpers.cs and then called it from the View like so:
Filter Children by Multinode Tree picker contents
I have a directory of companies, which have 2 properties which are got from multinode tree pickers, Country and Activity. The contents of these are displayed as a list of checkboxes, and I need to be able to filter the directory according to what is checked.
I am having difficulty getting my head around this. Code is as follows - (with lots of things like styling and accordions and pagination stripped out so there might be tags and brackets missing - the page does work as is without filtering)
I have 2 lists which get the parameters coming in and then combine to one list of what needs to be filtered against. I just don't know how to query the items in showItems helper function to only show these companies. ETA - Should I be able to write something like:
I'm getting "Exception Details: System.ArgumentNullException: Value cannot be null. "on this line
(using uskinned Source theme if that makes a difference)
This is a very old post but did you ever figure this out. Umbraco 8 and I am getting the same things with no real solutions that work that I can see.
I see from your other post that you found a solution. I was going to say that I ended up making a function:
And then in the view:
Will have to check out your solution too.
I saw your example and others where people tried to make a string or an array of the items and check in there but could not get it to work in Umbraco 8. The solution was to check the multinodepicker directly but because it may be empty sometimes and can not match an ID it through either an object error or value null error. Checking to ensure not null first in a where then running through works well.
Sorry for asking a probably silly question.
But did you place your function in a class?
I dont get the concept of spreading code logic in in views and.. classes, etc...
I put my function in a class, yes:
in a file called App_Code/MyHelpers.cs and then called it from the View like so:
Sometimes I'd have Models, Logic, Controllers etc but not in this case. HTH?
is working on a reply...