Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi guys
I am working on a memberlist. The list works fine. I now need to add some filtering. I have a dropdown where I get all the membergroups. I now want to add the membergroup as a css class on each member. My code looks like this:
@inherits Umbraco.Web.Macros.PartialViewMacroPage@using Umbraco.Core;@using Umbraco.Core.Models;@using Umbraco.Core.Services;@{ var memberservice = ApplicationContext.Current.Services.MemberService;}@* -- Bruger JS plugin fra listjs.com til at filtrere -- *@<div id="users"> <input class="search" placeholder="@Umbraco.Field("#Søg efter medarbejder")" /> <select> <option>Vælg en afdeling</option> @foreach (var memGroup in Roles.GetAllRoles()) { <option>@memGroup.ToString()</option> } </select> <div class="medarbejdereTH"> <span><strong>Navn</strong></span> <span><strong>Lokal</strong></span> <span><strong>Lokal mobil</strong></span> <span><strong>Mobil</strong></span> <span><strong>Mail</strong></span> </div> <div class="list medarbejdere"> @foreach (Member mem in memberservice.GetAllMembers().OrderBy(n => n.Name)) { <div class=""> <span class="name">@mem.Name</span> <span class="lokal">@mem.GetValue("lokal")</span> <span class="lokalM">@mem.GetValue("lokalMobil")</span> <span class="mobil">@mem.GetValue("medarbejderMobil")</span> <span class="mail"><a href="mailto:@mem.Email">@mem.Email</a></span> </div> } </div></div>
I have been looking at http://our.umbraco.org/documentation/Reference/Management-v6/Services/MemberService
But I can't figure out what to use.
How do I go about doing that?
/Michael
Hi Michael,
I haven't tested it but you could try the following:
@foreach (var member in ApplicationContext.Current.Services.MemberService.GetAllMembers().OrderBy(n => n.Name)) { var memberRoles = Roles.GetRolesForUser(member.Username); // Combine all member roles together, replacing space // characters with a hypen var memberCss = memberRoles .Aggregate(string.Empty, (current, memberRole) => string.Concat(current, memberRole.Replace(" ", "-"))); <div class="@memberCss"> <span class="name">@member.Name</span> <span class="lokal">@member.GetValue("lokal")</span> <span class="lokalM">@member.GetValue("lokalMobil")</span> <span class="mobil">@member.GetValue("medarbejderMobil")</span> <span class="mail"><a href="mailto:@mem.Email">@member.Email</a></span> </div> }
Hope that helps.
Thanks, Dan.
Hi Dan
Works like a charm :D
Thank you very very much.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Get membergroup for each member in memberlist
Hi guys
I am working on a memberlist. The list works fine. I now need to add some filtering. I have a dropdown where I get all the membergroups. I now want to add the membergroup as a css class on each member. My code looks like this:
I have been looking at http://our.umbraco.org/documentation/Reference/Management-v6/Services/MemberService
But I can't figure out what to use.
How do I go about doing that?
/Michael
Hi Michael,
I haven't tested it but you could try the following:
Hope that helps.
Thanks, Dan.
Hi Dan
Works like a charm :D
Thank you very very much.
/Michael
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.