Copied to clipboard

Flag this post as spam?

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


  • Adam Jenkin 71 posts 226 karma points
    Mar 06, 2013 @ 10:58
    Adam Jenkin
    0

    When is a DynamicNode dynamic?

    I am having an issue using dynamic nodes which have been added to a DynamicNodeList. Essentially after adding a dynamic node to the list, I cannot access the properties dynamically. I am using Umbraco version 4.7.4. Here is an example macroscript file which can reproduce the problem.

     

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext 
    <!-- TEST 1, access to .noSeach propery works lovely :) -->
    <ul>
      <li>My variable type is .. "@Model.GetType()"</li>
      <li>Current page is .. "@Model.Id"</li>
      <li>Here is a property retireved through dynamic .. "@Model.noSearch"</li>
    </ul>
    @{
    var newNode = new DynamicNode(Model.Id);
    }
    <!-- TEST 2, access to .noSeach propery throws an error message :( -->
    <ul>
      <li>My variable type is .. "@newNode.GetType()"</li>
      <li>Current page is .. "@newNode.Id"</li>
      @* uncommenting this line throws an error.. why?  
        <li>Here is a property retireved through dynamic .. "@newNode.noSearch"</li> *@
    </ul>

     

    Perpahs I am incorrectly using or misunderstanding when I can use Dyanmic property, is the 'dynamicness' only available on Model?

     

  • Adam Jenkin 71 posts 226 karma points
    Mar 06, 2013 @ 11:49
    Adam Jenkin
    101

     

    Doh! - seems like I dont know my dynamics! 

    Solved by using the dynamic keyword instead of var.. so

     

    @{
            // var newNode =newDynamicNode(Model.Id);
    dynamic newNode = new DynamicNode(Model.Id);
    }

     

     

Please Sign in or register to post replies

Write your reply to:

Draft