Using a Linq GroupBy, you could do something like:
@{
var members = Member.GetAll;
var col = members.GroupBy(x => x.GetProperty<string>("title"));
foreach (var group in col)
{
<h2>@group.Key (@group.Count())</h2>
foreach(var item in group)
{
<h3>@item.LoginName</h3>
}
}
}
There are some great examples of different Linq samples here
Iterating through members based on Custom fields... help required.
Hi all just trying to get my head around Razor and Members.
I am trying to count all members from any given area, or list all distinct areas members are in.
So I know how to list all areas such as...
@{
var members = Member.GetAll;
foreach(var member in members)
{
<p>@member.getProperty("memberCity").Value</p>
}
}
But is there a simple way using Razor to say...
list all distinct memberCity
and count all where memberCity = Glasgow
I don't know how to use the getProperty("memberCity").Value anywhere but once a member is in the loop.
I hope this makes sense to someone, who could point me in the right direction for the syntax or wether this is indeed possible.
Cheers
Doogie
Hi Doogie,
You could do something like this:
I would also recommend you take a look at the uQuery members methods here as they are very useful.
Jeavon
I would not recommend doing things like Member.GetAll();
Its really expensive in terms of resources. You dont need to get every result just do a experssion.. Jeavons example is what you need :).
Really helpful guys just looking on the uQuery section seems to cover most of what I need.
1 last queston though. As this returns members how for exampe would you go about returning properties of the members.
Specifically want to list all the unique/distinct memberCity from all members. Is this possible ?
Basically I want to return the citys that members are in and show a count next to it.
If you have a code example that would be great as it would help further down the line with other queries I need to do.
Thanks for your help so far.
Doogie
Hi Doogie,
Using a Linq GroupBy, you could do something like:
There are some great examples of different Linq samples here
Thanks,
Jeavon
Thanks, that all slotted into place. I simple removed title and put in memberCity and it worked perfectly.
I will be putting these values into google maps api too so the group mechanism is perfect.
Thanks very much for your help and the links.
Doogie.
is working on a reply...