I think from the fact that you are getting umbraco.MacroEngines.DynamicXml means you are using a Razor Macro rather than a MVC view.
So, if you using Umbraco 4.10+ then you should be able to check if(item.link.link.contentPicker.Any()) If you are using a earlier version you will need to do a count check, something like if(item.link.link.contentPicker.Count() > 0)
var strimg = Library.MediaById(item.umbracofile); var strimge = @strimg.url; var linkxml = item.link.link.contentPicker; var linkid = linkxml; var strtekst = item.bodyText; var stroverskrift = item.overskrift; var strfyld = item.fyld;
Oh one further thought, if you are using 4.11.5 you need to update your umbraco.MacroEngines.dll to the one from 4.11.6 nightly as there is a major issue using Razor Macos otherwise. More info here http://issues.umbraco.org/issue/U4-1824
umbracoMacro Error Loading Razor Script (file: Forside Teasers) 'string' does not contain a definition for 'Any' at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at ASP._Page_macroScripts_forsideTeasers_cshtml.Execute() in d:\web\localuser\lykkenvej5.dk\public_html\macroScripts\forsideTeasers.cshtml:line 36 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) 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) 0,786868 0,050583 macro Error loading MacroEngine script (file: forsideTeasers.cshtml, Type: '' 'string' does not contain a definition for 'Any' at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at ASP._Page_macroScripts_forsideTeasers_cshtml.Execute() in d:\web\localuser\lykkenvej5.dk\public_html\macroScripts\forsideTeasers.cshtml:line 36 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) 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)
@using umbraco;
@using umbraco.MacroEngines;
@{
var test = "<thing><widget isCollapsed=\"false\"><filemediatype>1</filemediatype><overskrift>text</overskrift><fyld>text</fyld><umbracofile /><mediaVaelger /><link><contentPicker><content>1100</content></contentPicker></link><bodyText>text</bodyText></widget></thing>";
var test1 = new DynamicXml(test);
var list = test1;
foreach (dynamic item in list)
{
<p>@item.link.contentPicker.Any().ToString()</p>
if(item.link.contentPicker.Any()){
<p>@item.link.contentPicker.content</p>
}
<p>@item.link.contentPicker.content</p>
}
}
umbracoMacro Error Loading Razor Script (file: Forside Teasers) 'string' does not contain a definition for 'Any' at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at ASP._Page_macroScripts_forsideTeasers_cshtml.Execute() in d:\web\localuser\lykkenvej5.dk\public_html\macroScripts\forsideTeasers.cshtml:line 10 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) 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) 0,439237 0,012133 macro Error loading MacroEngine script (file: forsideTeasers.cshtml, Type: '' 'string' does not contain a definition for 'Any' at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at ASP._Page_macroScripts_forsideTeasers_cshtml.Execute() in d:\web\localuser\lykkenvej5.dk\public_html\macroScripts\forsideTeasers.cshtml:line 10 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) 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)
check if empty XML
this is the xml
var linkxml = item.link.link.contentPicker;
out comes
umbraco.MacroEngines.DynamicXml
and then I @Model.NodeById(linkid); but if "item.link.link.contentPicker" is empty it produces an error
how do I check if "item.link.link.contentPicker" is empty
Hi what language are you using? XSLT or MVC(Razor)? Are you in a partial view or a view or controller? What are you trying to do?. Thanks. Charlie :)
it is in Razor
partial view or a view or controller ?????
to see if it is empty
Hi Brian,
I think from the fact that you are getting umbraco.MacroEngines.DynamicXml means you are using a Razor Macro rather than a MVC view.
So, if you using Umbraco 4.10+ then you should be able to check if(item.link.link.contentPicker.Any()) If you are using a earlier version you will need to do a count check, something like if(item.link.link.contentPicker.Count() > 0)
Hope that helps?
Jeavon
I use umbraco 4.11.5
i get this error if i use Any()
'string' does not contain a definition for 'Any'
or
Cannot implicitly convert type 'umbraco.MacroEngines.DynamicNode' to 'string'
Brian, can you post you whole Razor snippet?
@using umbraco.MacroEngines;
@using umbraco.MacroEngines.Library;
@{
var list = @Model.teaser;
foreach (var item in list)
{
var strimg = Library.MediaById(item.umbracofile);
var strimge = @strimg.url;
var linkxml = item.link.link.contentPicker;
var linkid = linkxml;
var strtekst = item.bodyText;
var stroverskrift = item.overskrift;
var strfyld = item.fyld;
if(item.link.link.contentPicker.Any()){
linkurl = @Model.NodeById(linkid);
}
@linkurl.url
}
}
Ok, just one too many link, this should work:
if(item.link.contentPicker.Any()){
linkurl = @Model.NodeById(item.link.contentPicker.content).Url
}
Oh one further thought, if you are using 4.11.5 you need to update your umbraco.MacroEngines.dll to the one from 4.11.6 nightly as there is a major issue using Razor Macos otherwise. More info here http://issues.umbraco.org/issue/U4-1824
Okay where do I find 4.11.6
http://umbraco.codeplex.com/releases/ has only 4.11.5 or 6.0.2
Get it from here http://nightly.umbraco.org/umbraco%204.11.6/UmbracoCms.4.11.6-build.11.zip You only need to update umbraco.MacroEngines.dll
now i get error
Error loading MacroEngine script (file: forsideTeasers.cshtml)
Can you add ?umbDebugShowTrace=true to your url to get some detail of the error?
You need to have umbracoDebugMode set to true in web.config
there comes no more information
Do you see the trace if you scroll down the page, you should find a red section with details of the error?
Strange, can you try this:
then i get
True
1100
1100
Ok, so to check then, your xml fragment elementis a item within a list of items?
If you change var list = test1; to var list = Model.teaser; does it work?
no then i get this
umbracoMacro Error Loading Razor Script (file: Forside Teasers) 'string' does not contain a definition for 'Any' at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at ASP._Page_macroScripts_forsideTeasers_cshtml.Execute() in d:\web\localuser\lykkenvej5.dk\public_html\macroScripts\forsideTeasers.cshtml:line 10
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
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) 0,439237 0,012133
macro Error loading MacroEngine script (file: forsideTeasers.cshtml, Type: ''
'string' does not contain a definition for 'Any'
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at ASP._Page_macroScripts_forsideTeasers_cshtml.Execute() in d:\web\localuser\lykkenvej5.dk\public_html\macroScripts\forsideTeasers.cshtml:line 10
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
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)
Got it! It is a bug in DynamicXml, I will report the issue.
Meanwhile, here is a workaround for you:
if(item.link.contentPicker.GetType() == typeof(DynamicXml) &&item.link.contentPicker.Any()){
<p>@item.link.contentPicker.content</p>
}
I have modified the data type so I only have to call the link if a drop down box is set too yes
but many thanks for the help
yes it works :-)
Great!
is working on a reply...