Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Amir Khan 1289 posts 2746 karma points
    Nov 21, 2013 @ 00:34
    Amir Khan
    0

    Alphabetical list of members

    Is there a way to alphabetically a list of members by name or last name (custom property) in razor?

    Here's how I'm getting a list of all members.

    <ul class="memberList">
    @foreach (var member in allMembers)
    {

    var currentMember = new Member(Convert.ToInt32(@member.Id));
    <li class="clearfix">
    <figure class="headshot small">
    @{
    if (@currentMember.getProperty("memberPhoto").Value != String.Empty) {
    <img src="@currentMember.getProperty("memberPhoto").Value" alt="@currentMember.Text" width="140" />
    }

    else {
    <img src="@(currentMember.Email.GetGravatarUrl(250, string.Empty))&d=http%3A%2F%2Fccup.blackswaninteractive.com%2Fimages%2Fheadshot-placeholder.jpg" alt="@currentMember.Text" width="140" />
    }
    }
    </figure>
    <div class="profile small">
    @if (Umbraco.MemberIsLoggedOn()){
    <h2><a href="/profiles/[email protected]">@member.Text @currentMember.getProperty("lastName").Value</a></h2>
    }
    else {
    <h2>@member.Text</h2>
    <p>Please <a href="/register/">sign up</a> or <a href="/login/">login</a> to see full profiles.</p>
    }

    </div>
    </li>
    }
    </ul>
  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 21, 2013 @ 08:26
    Fuji Kusaka
    103

    Hi Amir,

    Yes could do make the sorting like this

    foreach(Member m in members.Where(x => x.HasProperty("userFirstName") && x.getProperty("userFirstName").Value.ToString() != String.Empty).OrderBy(x=>x.getProperty("userFirstName").Value.ToString())){
    @m.Text or @m.getProperty("userFirstName").Value.ToString()
    }
  • Amir Khan 1289 posts 2746 karma points
    Nov 25, 2013 @ 18:14
    Amir Khan
    0

    Fuji, thank you. This worked great!

  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 25, 2013 @ 18:20
    Fuji Kusaka
    0

    Most Welcome Amir, glad you solve this. :)

  • 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.

Please Sign in or register to post replies