@Levente you don't mention what the issue is? Do you get an error or do you just not get a list of unique values? If the value is numeric you can cast it as follows (not that it should rectify whatever issue you are having).
foreach (var plot in plots.Select(x => x.Value<int>("bedrooms")).Distinct()) {
<p>@plot</p>
}
I just realised that around this foreach there is another foreach, so maybe that causes the issue, which is "the list values are not unique". There are duplications.
So here is my full code, now added the <int> as well.
var developments = Model.Root().Children.Where(x => x.IsDocumentType("developments")).FirstOrDefault();
foreach (var development in developments.Children.Where(x => x.IsVisible())) {
var plots = development.Children.Where(x => x.IsVisible() && x.Value<bool>("plotApartment"));
foreach (var plot in plots.Select(x => x.Value<int>("bedrooms")).Distinct())
{
<p>@plot</p>
}
}
Remove duplications form list
Hi,
I try to figure out how to remove duplications from this list, but I can't. I though I can use distinct like here:
Any idea how should I fix it?
Hi,
What type of datatype is bedrooms property. If it has been string or integer then it will allow but if it is iPublishedContent then it will not work.
Please can you confirm.
Regards,
Shaishav
Hi,
It's a numeric field.
Thanks, Levente
So should it work with this code?
@Levente you don't mention what the issue is? Do you get an error or do you just not get a list of unique values? If the value is numeric you can cast it as follows (not that it should rectify whatever issue you are having).
I just realised that around this foreach there is another foreach, so maybe that causes the issue, which is "the list values are not unique". There are duplications.
So here is my full code, now added the
<int>
as well.Sorry, early start this morning and overlooked the original code...
You don't need a foreach to get a distinct list of bedrooms, just select them like this.
is working on a reply...