Copied to clipboard

Flag this post as spam?

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


  • Brian Olsen 143 posts 424 karma points
    Mar 23, 2013 @ 16:44
    Brian Olsen
    0

    check if empty XML

    this is the xml

            <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>

    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

     

  • Charles Afford 1163 posts 1709 karma points
    Mar 23, 2013 @ 16:56
    Charles Afford
    0

    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 :)

  • Brian Olsen 143 posts 424 karma points
    Mar 23, 2013 @ 17:07
    Brian Olsen
    0

    it is in Razor

    partial view or a view or controller ?????

    to see if it is empty

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 23, 2013 @ 17:13
    Jeavon Leopold
    0

    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

  • Brian Olsen 143 posts 424 karma points
    Mar 23, 2013 @ 17:46
    Brian Olsen
    0

    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'

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 23, 2013 @ 17:55
    Jeavon Leopold
    0

    Brian, can you post you whole Razor snippet?

  • Brian Olsen 143 posts 424 karma points
    Mar 23, 2013 @ 18:54
    Brian Olsen
    0

    @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

    }

    }

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 23, 2013 @ 19:18
    Jeavon Leopold
    0

    Ok, just one too many link, this should work:

    if(item.link.contentPicker.Any()){
    linkurl = @Model.NodeById(item.link.contentPicker.content).Url

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 23, 2013 @ 19:22
    Jeavon Leopold
    0

    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

     

  • Brian Olsen 143 posts 424 karma points
    Mar 23, 2013 @ 20:01
    Brian Olsen
    0

    Okay where do I find 4.11.6

    http://umbraco.codeplex.com/releases/ has only 4.11.5 or 6.0.2

     
    or should I take it from 4.11.4
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 23, 2013 @ 20:04
    Jeavon Leopold
    0

    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 

  • Brian Olsen 143 posts 424 karma points
    Mar 23, 2013 @ 20:48
    Brian Olsen
    0

    now i get error

    Error loading MacroEngine script (file: forsideTeasers.cshtml)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 23, 2013 @ 20:51
    Jeavon Leopold
    0

    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

  • Brian Olsen 143 posts 424 karma points
    Mar 23, 2013 @ 20:57
    Brian Olsen
    0

    there comes no more information

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 23, 2013 @ 21:00
    Jeavon Leopold
    0

    Do you see the trace if you scroll down the page, you should find a red section with details of the error?

  • Brian Olsen 143 posts 424 karma points
    Mar 23, 2013 @ 21:05
    Brian Olsen
    0
    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)
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 23, 2013 @ 21:24
    Jeavon Leopold
    0

    Strange, can you try this:

        @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>
      }   
      } 
  • Brian Olsen 143 posts 424 karma points
    Mar 23, 2013 @ 21:40
    Brian Olsen
    0

    then i get

    True

    1100

    1100

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 23, 2013 @ 21:45
    Jeavon Leopold
    0

    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?

  • Brian Olsen 143 posts 424 karma points
    Mar 23, 2013 @ 21:49
    Brian Olsen
    0

    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)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 23, 2013 @ 21:57
    Jeavon Leopold
    100

    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>  

        } 

  • Brian Olsen 143 posts 424 karma points
    Mar 23, 2013 @ 21:59
    Brian Olsen
    0

    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

  • Brian Olsen 143 posts 424 karma points
    Mar 23, 2013 @ 22:02
    Brian Olsen
    0

    yes it works :-)


  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 23, 2013 @ 23:29
    Jeavon Leopold
    0

    Great!

Please Sign in or register to post replies

Write your reply to:

Draft