Copied to clipboard

Flag this post as spam?

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


  • umbracocool 108 posts 197 karma points
    Jun 19, 2013 @ 21:51
    umbracocool
    0

    Sort by price razor

    Hey guys!

     

    I want to do a sort by price whose format is:

     

    12,000

    31,500

    1.500,300

    (to cite one example).

    The field is called "price", but tengoe ste c'dogio and does not work:

    nodes = Model.NodeById(1150).Descendants("Car").OrderBy("price desc");

    and the problem rests solely with the "OrderBy".

     

    Help please!.

    Regards!.

     

     

  • Mark 49 posts 130 karma points
    Jun 19, 2013 @ 22:23
    Mark
    0

    probably something like 

    Model.NodeById(1150).Descendants("Car").OrderByDescending(x => x.GetPropertyValue<double>("price"));

     

  • umbracocool 108 posts 197 karma points
    Jun 19, 2013 @ 22:30
    umbracocool
    0

    Thank bro. Look, to save it, show this error: 

    error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

  • Mark 49 posts 130 karma points
    Jun 19, 2013 @ 23:15
    Mark
    0

    Oh right think you using dynamic model instead of IPublishedContent, no worries, try using price as a dyanamic field.

    ie.

    Model.NodeById(1150).Descendants("Car").OrderByDescending(x => (double)x.price);
  • umbracocool 108 posts 197 karma points
    Jun 19, 2013 @ 23:42
    umbracocool
    0

    I have this code:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @using EasyTumb;

    @using umbraco.MacroEngines;

    @using umbraco.NodeFactory;

    @using Refactored.UmbracoViewCounter;

    Model.NodeById(1150).Descendants("Car").OrderByDescending(x =>(double)x.price);

    But... donĀ“t work!

    I get this error: 

    macroScripts\635072569961203807_DealerPagination.cshtml(61): error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

  • Mark 49 posts 130 karma points
    Jun 20, 2013 @ 01:07
    Mark
    0

    yeah... using dynamic causes problems with linq.

    I'd go for something like the following so you have properly typed objects

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @Umbraco.TypedContent(1150).Descendants("Car").OrderByDescending(x => x.GetPropertyValue<double>("price"));
  • umbracocool 108 posts 197 karma points
    Jun 20, 2013 @ 01:44
    umbracocool
    0

    Thank you bro for you time. :D

    With this:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @Umbraco.TypedContent(Model.Id).Descendants("Car").OrderByDescending(x => x.GetPropertyValue("price"));

    I getting this:

    \macroScripts\635072642210605166_DealerPagination.cshtml(3): error CS0234: The type or namespace name 'TypedContent' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)

  • Fuji Kusaka 2203 posts 4220 karma points
    Jun 20, 2013 @ 08:33
    Fuji Kusaka
    0

    Change this 

    @Umbraco.TypedContent(Model.Id).Descendants("Car").OrderByDescending(x => x.GetPropertyValue("price"));

    to

    @Umbraco.TypedContent(Model.Id).Descendants("Car").OrderByDescending(x => x.getProperty("price"));
  • umbracocool 108 posts 197 karma points
    Jun 20, 2013 @ 08:39
    umbracocool
    0

    Thank... but the problem is this: error CS0234: The type or namespace name 'TypedContent' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 20, 2013 @ 13:27
    Jeavon Leopold
    3

    Hi, looks like you are using a Razor macro rather than MVC which is why you don't have TypedContent. However you can do something similar in a Razor macro by using uQuery (Umbraco 4.8+):

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines
    @using umbraco;
    @using umbraco.NodeFactory;
    
    @{
        var nodes = uQuery.GetNode(1150).GetDescendantNodes(n => n.NodeTypeAlias == "Car").OrderByDescending(x => x.GetProperty<double>("price"));
    }

     

Please Sign in or register to post replies

Write your reply to:

Draft