Copied to clipboard

Flag this post as spam?

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


  • Mr A 216 posts 278 karma points
    Oct 06, 2011 @ 13:16
    Mr A
    0

    Cannot Implicity Convert Error using Razor Macro

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using System
    @using System.Linq
    @using System.Xml.Linq
    @{
      dynamic node new umbraco.MacroEngines.DynamicNode(1121);
      
      }


    @foreach (dynamic group in node.Children.OrderBy("CreatedDate").Take(2))
    {
        <div class="column-holder">
        @foreach (var item in group )
        {
              <div class="cell">
               
                 <h3>@item.Name</h3>
                <em>@String.Format("{0:dddd, MMMM d yyyy}"item.EventDateTimeStarts at @String.Format("{0:HH:mm}"item.EventDateTime)</em><br />
                <span>@(Library.Truncate(Library.StripHtml(item.EventDescription)50true))</span>
                 <class="readmore-link"><href="@item.Url" class="link more">read more</a></p>      
              
               </div>
                     
         
        }
        </div>
    }

    The following error I get when i try to run the above micro on homepage:

    Error loading Razor Script ~/macroscripts/eventhomepage.cshtml
    Cannot implicitly convert type 'umbraco.MacroEngines.DynamicNode' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?)


  • Rodion Novoselov 694 posts 859 karma points
    Oct 06, 2011 @ 14:51
    Rodion Novoselov
    0

    Hi. It seems to me that the problem lies in the expression 'node.Children.OrderBy("CreatedDate").Take(2)'. Since 'node' is declared as a dynamic, the 'Children' property and following methods are all called dynamicaly. I would recomend to try and check (e.g. inside a dubugger) what a runtime type exactly is returned by the 'Children' property. (Or probably someone here know it for sure and can help, because personally I'm not that strong in using Razor along with Umbraco API).

     

  • Mr A 216 posts 278 karma points
    Oct 06, 2011 @ 17:03
    Mr A
    0

    I managed to solve it, below is the code:

    @inherits umbraco.MacroEngines.DynamicNodeContext


    @foreach (var item in @Model.NodeById(1121).Children.OrderBy("EventDateTime").Take(2))
    {
        <div class="column-holder">
       
              <div class="cell">
               
                 <h3>@item.Name</h3>
                <em>@String.Format("{0:dddd, MMMM d yyyy}"item.EventDateTimeStarts at @String.Format("{0:HH:mm}"item.EventDateTime)</em><br />
                <span>@(Library.Truncate(Library.StripHtml(item.EventDescription)50true))</span>
                 <class="readmore-link"><href="@item.Url" class="link more">read more</a></p>      
              
               </div>
                     
         
        
        </div>
    }

Please Sign in or register to post replies

Write your reply to:

Draft