Copied to clipboard

Flag this post as spam?

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


  • Garret 69 posts 309 karma points
    Apr 03, 2013 @ 19:31
    Garret
    0

    Orderby on nodeproperty that's a Xpath Dropdownlist

    Hi,

    How can i do an OrderBy on a property (in this case 'Type') of a node which is of type "Xpath Dropdownlist".

    I tried Model.Artikels.OrderBy("type") but it gave an "At least one object must implement IComparable".

    Tnx in advance!
    Garret


  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Apr 03, 2013 @ 20:03
    Lee Kelleher
    0

    Hi Garret,

    I'm not exprt in the "DynamicNode" (old) Razor, but you may need to use a lambda expression?

    Model.Artikels.OrderBy(x => x.GetProperty<string>("type"));

    Cheers, Lee.

  • Garret 69 posts 309 karma points
    Apr 03, 2013 @ 20:34
    Garret
    0

    Hi Lee,

    According to http://umbraco.com/follow-us/blog-archive/2011/3/1/umbraco-razor-feature-walkthrough-%E2%80%93-part-4.aspx that's not possible.

    ///

    With DynamicObject (DynamicNode too, because it inherits from), the c# compiler / razor parser doesn't allow you to use the familiar lambda syntax to filter your sets.
    This is because we now return a DynamicObject [DynamicNodeList] to allow method chaining.

    This will not work in 4.6.1 or 4.7.

    @Model.Children.Where(item => item.shouldBeFeatured);
     
    //Lambda's cannot be used against Dynamic Objects
    But i will give it a try.
    Tnx for the effort
  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Apr 03, 2013 @ 20:56
    Lee Kelleher
    0

    Ah ok, not too sure how it should work - sorry.  Hopefully someone else can jump on this with better knowledge. :-)

  • 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