Copied to clipboard

Flag this post as spam?

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


  • Johan Plesner Hamann 105 posts 199 karma points
    Jul 10, 2011 @ 12:51
    Johan Plesner Hamann
    0

    Multi-Node Tree Picker if it is empty..

     

    hey guys

    I have a Multi-Node Tree Picker and it is empty, this gives an error.

        foreach (var in item.refKursus
       {
         var @Model.NodeById(@x.InnerText);
         var nSta =@n.kursusStartDato.ToString("dd");
         var nEnd @n.slutDato.ToString("dd. MMMM yyyy");
         <em class="date">@nSta<text>.</text@nEnd</em>
     
      }

     

    Error loading Razor Script BlockHolding.cshtml
    Input string was not in a correct format.

     


    What can solve this? I will try if else but null and "" gives me  an error.

    Error loading Razor Script BlockHolding.cshtml
    Operator '!=' cannot be applied to operands of type 'umbraco.MacroEngines.DynamicXml' and 'string

    Many thanks

    /Johan 

     

  • Bert 128 posts 251 karma points
    Jul 10, 2011 @ 12:58
    Bert
    1
     @if (@Model.HasProperty("mntpicker") && @Model.GetProperty("mntpicker").Value != String.Empty){
            <ul>
             @foreach (XElement elem in Model.mntpicker.BaseElement.Elements("nodeId"))
             {
               var theNodeInSideThePicker = @Model.NodeById(elem.Value);         
               <li>
                 @theNodeInSideThePicker.Name
               </li>
             }
            </ul>
    }
    1. Check first if the property exists and has a value
    2. Run over the xml inside the propertyvalue
    3. Get the nodes inside the picker by those ID's
    4. Do your stuff
  • Johan Plesner Hamann 105 posts 199 karma points
    Jul 10, 2011 @ 13:05
    Johan Plesner Hamann
    0

    Thank you Bert, it was just what was needed!

    my code is now:

    @if (@item.HasProperty("refKursus"&@item.GetProperty("refKursus").Value != String.Empty)
    {

      foreach (var in item.refKursus
      {
      
          var @Model.NodeById(@x.InnerText);
          var nSta =@n.kursusStartDato.ToString("dd");
          var nEnd @n.slutDato.ToString("dd. MMMM yyyy");
          <em class="date">@nSta<text>.</text@nEnd</em>
      }
    }

     

    /Johan

  • maanehunden 61 posts 105 karma points
    Sep 20, 2012 @ 10:29
    maanehunden
    0

    Her's my 5 cents 

    @if (@item.HasValue("refKursus"))
    {
        // do your stuff
    }
    

    Hope it will help some one (c:

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies