I am working on a member list. So far everything works fine. I now want to add sorting on it. I have a custom property on my members that use the numeric datatype in umbraco. The alias on it is sortering. I thought it was a simple as doing .OrderBy("sortering"). Anyway here is my code:
Using Umbraco 7.2.2, when I try to OrderBy I get the following error:
error CS1928: 'System.Collections.Generic.IEnumerable' does not contain a definition for 'OrderBy' and the best extension method overload 'Umbraco.Web.PublishedContentExtensions.OrderBy(System.Collections.Generic.IEnumerable, string)' has some invalid arguments
I have everything setup exactly as in the above example, except that I want to sort on a string field (company). Can anyone help?
Sort memberlist by custom property
Hi guys
I am working on a member list. So far everything works fine. I now want to add sorting on it. I have a custom property on my members that use the numeric datatype in umbraco. The alias on it is sortering. I thought it was a simple as doing .OrderBy("sortering"). Anyway here is my code:
Any ideas? :)
/Michael
Hi Michael,
You will need you use a lambda such as this:
Jeavon
I can get it to work if I add a .ToString() like this:
@foreach (var mem in memberservice.GetAllMembers().OrderBy(x => x.GetValue("sortering").ToString()))The problem now is that the number 10-19 gets displayd before number 2. I am guessing it's because it only looks at the first number?
Did you get an error when using it like this?
Ahhh yes, that did it.
Thank you very much Jeavon :D
Brilliant!
I don't think it would help you with what you are doing here but are you also aware of the new MembershipHelper?
Jeavon
No, but now i am. Thank you very much :)
Michael
Using Umbraco 7.2.2, when I try to OrderBy I get the following error:
I have everything setup exactly as in the above example, except that I want to sort on a string field (company). Can anyone help?
Hi Mike,
Could you post your code?
Jeavon
@inherits Umbraco.Web.Macros.PartialViewMacroPage @using Umbraco.Core; @using Umbraco.Core.Models; @using Umbraco.Core.Services; @{ var memberService = ApplicationContext.Current.Services.MemberService; var members = memberService.GetMembersByGroup("1"); string contact = String.Empty; string company = String.Empty; string address = String.Empty; string citystzip = String.Empty; string phone = String.Empty; string fax = String.Empty; string cleanphone = String.Empty; string cleanfax = String.Empty; int counter = 1; } @foreach ( Member currentMember in members ) { try { if(currentMember.HasProperty("company")) { contact = currentMember.GetValue("contact").ToString(); } } catch {} try { if(currentMember.HasProperty("company")) { company = currentMember.GetValue("company").ToString(); } } catch {} try { if(currentMember.HasProperty("company")) { address = currentMember.GetValue("address").ToString(); } } catch {} try { if(currentMember.HasProperty("company")) { citystzip = currentMember.GetValue("citystzip").ToString(); } } catch {} try { if(currentMember.HasProperty("company")) { phone = currentMember.GetValue("phone").ToString(); phone = phone.Replace("(", ""); phone = phone.Replace(")", ""); phone = phone.Replace(" ", ""); phone = phone.Replace("-", ""); cleanphone = String.Format( "{0:(###) ###-####}", Convert.ToInt64(@phone) ); } } catch {} try { if(currentMember.HasProperty("company")) { fax = currentMember.GetValue("fax").ToString(); fax = fax.Replace("(", ""); fax = fax.Replace(")", ""); fax = fax.Replace(" ", ""); fax = fax.Replace("-", ""); cleanfax = String.Format( "{0:(###) ###-####}", Convert.ToInt64(@fax) ); } } catch {} <article class="AssociateBox"> <span class="AssociateName">@company</span><br /> <span class="AssociateContactInfo">@contact</span><br /> <span class="AssociateContactInfo">@address</span><br /> <span class="AssociateContactInfo">@citystzip</span><br /> <span class="AssociateContactInfo">Phone: @cleanphone</span><br /> <span class="AssociateContactInfo">Fax: @cleanfax</span><br /> </article> counter++; if ( counter == 4 ) { <div class="ClearBoth"></div> counter = 1; } }When I try adding the OderBy to GetMembersByGroup("1") I get the error.
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.