Copied to clipboard

Flag this post as spam?

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


  • Toni Becker 146 posts 425 karma points
    Mar 31, 2011 @ 12:59
    Toni Becker
    0

    Issue using Model.Children.Take(var)

    Is this supported via razor to define a macroparameter passing it to a var and then pull it inside the take method.

    Here's what i'm trying to do.

    @{ var numOfItems = @Parameter.numberOfItems }

    @foreach (var item in @Model.Children.Where("umbracoNaviHide != 1").Take(numOfItems))

    { some basic HTML Markup <p>@item.nodeName</p>}

    But throws an error :

    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Take".
    When i change to Take(5) it works, but passing macroparam would be nicer.

  • Alex 78 posts 136 karma points
    Mar 31, 2011 @ 13:03
    Alex
    0

    Have you tried casting numOfItems as an int?

    @{ int numOfItems = @Parameter.numberOfItems }
  • Toni Becker 146 posts 425 karma points
    Mar 31, 2011 @ 13:07
    Toni Becker
    0

    yep but not working. This was my first idea passing it as an int but throws that
    Error loading Razor Script 1.cshtml Cannot implicitly convert type 'string' to 'int'

  • Alex 78 posts 136 karma points
    Mar 31, 2011 @ 13:10
    Alex
    0

    What about if you use this

    @{ int numOfItems = int.Parse(@Parameter.numberOfItems) }

  • Toni Becker 146 posts 425 karma points
    Mar 31, 2011 @ 13:17
    Toni Becker
    0

    That was the solution. OMG just so simple <- slap me around the world :p

    Thanks Alex

  • Alex 78 posts 136 karma points
    Mar 31, 2011 @ 13:26
    Alex
    0

    No problem, sometimes it's hard to forget about Razor, Umbraco, DynamicNodes etc... and just think about good old C#! ;-)

Please Sign in or register to post replies

Write your reply to:

Draft