Copied to clipboard

Flag this post as spam?

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


  • Allan Michaelsen 14 posts 33 karma points
    Mar 04, 2011 @ 01:03
    Allan Michaelsen
    0

    Checking for dynamic child nodes

    I would like to know if it's possible to check ig a page has specific child nodes. I have something like this:

    @{
    if
    (Model.someDocName != null && Model.someDocName.Count() > 0)
    {
    some code...
    }

    But i keep getting this error: Cannot perform runtime binding on a null reference.

    Is it not possible to check for the specific child node or what's the trick to doing so.

  • Gareth Evans 143 posts 335 karma points c-trib
    Mar 09, 2011 @ 08:01
    Gareth Evans
    0

    What version? I think this is fixed in RC1

  • Allan Michaelsen 14 posts 33 karma points
    Mar 09, 2011 @ 20:24
    Allan Michaelsen
    0

    I use RC1 with all Razor scripts, but a couple of things bugs me sometimes, this being one of them... :D

  • Gareth Evans 143 posts 335 karma points c-trib
    Mar 09, 2011 @ 21:49
    Gareth Evans
    0

    In RC1, the return type will be DynamicNull when no property or children exist.

    I've checked your syntax and it indeed doesn't work in RC1.

    This is because

    if(Model.someDocName != null [true; DynamicNull != null] && Model.someDocName.Count() [error; .Count doesn't exist on DynamicNull] > 0)
    {
      some code
    ...

    RC2 is just around the corner, and I have already added support for accessing properties off a DynamicNull

    Model.someDocName.Count => DynamicNull

    To solve the requirement, i've also added a .Count() function, .IsNull property and .HasValue (reverse of IsNull) property.

    This lets your original syntax work.

    For now, if you do this:

    @using umbraco.MacroEngines

    if(Model.someDocType.GetType() != typeof(DynamicNull))
    {

    ...

    }

    Then it will behave how you expect in RC1 and RC2

     

  • Allan Michaelsen 14 posts 33 karma points
    Mar 12, 2011 @ 10:57
    Allan Michaelsen
    0

    Thanks Gareth

    I'll look forward to the next release... :)

    I would like to say this was solve, but i can't see the check mark to do so... But i consider it a satisfying answer.

     

  • Allan Michaelsen 14 posts 33 karma points
    Mar 12, 2011 @ 10:58
    Allan Michaelsen
    0

    DO' allready marked as solve... My bad...

Please Sign in or register to post replies

Write your reply to:

Draft