I am having a weird issue, hoping you all have some pointers. I am using Umbraco 4.11.10 and trying to fulfill a requirement to display 1 random quote from a collection of quotes. The really puzzling thing is that this exact code works on a different site using the same version of Umbraco.
The Quote object only has two properties...quoteText and quoteSignature. Here is my entire razor script (which currently fails).
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var item = @Model.NodeById(1113).Children.Random();
<div>
<blockquote>@item.quoteText<span>- @item.quoteSignature</span></blockquote>
</div>
}
If I strip out the div and block quote and all of that and just leave
var item = @Model.NodeById(1113).Children.Random();
it still fails.
If I remove Random() and output the @item variable it is a DynamicNodeList. If I do something like..
foreach(var child in item)
{
<div>
<blockquote>@child.quoteText<span>- @child.quoteSignature</span></blockquote>
</div>
}
It works, but of course I get all of the quotes. So I guess that at least proves that the data is valid, and the property names are valid. Just seems to be an issue using Random(). As I am pretty new to Razor I'm hoping this is just an oversight on my part.
*UPDATE * The error from the error log is as follows
2013-09-03 19:34:00,142 [11] WARN umbraco.macro - [Thread 24] Error loading MacroEngine script (file: CFRandomQuote.cshtml, Type: ''. Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Random'
at CallSite.Target(Closure , CallSite , Object , Int32 )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at ASP._Page_macroScripts_CFRandomQuote_cshtml.Execute() in c:\inetpub\cf\macroScripts\CFRandomQuote.cshtml:line 5
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
at umbraco.macro.loadMacroScript(MacroModel macro)
at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
Thanks Everyone!
@child.quoteText
etc. in the code not@item.
? – Digbyswift