Copied to clipboard

Flag this post as spam?

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


  • Carlos 338 posts 472 karma points
    Mar 25, 2013 @ 18:50
    Carlos
    0

    Probably easy fix but driving me crazy. String outputting umbraco.MacroEngines.DynamicXML

    I am having an issue with my media elements. We added a 'caption' property to the image MediaType.

    We are using a multiline textbox NOT the RTE for the property. We are haivng issues that, if the textbox is left empty, the string output is umbraco.MacroEngines.DynamicXml.

    Why would this be happening. There are not spaces, returns or anything in these boxes. 

    I have tried multiple ways to check for empty or null and they all still output the same string output if left empty.

    Same thing is happening in our AltTag property, if left blank it outputs the umbraco.MarcroEngines.dynamicXml

    My code is below. Any suggestions would be greatly appreciated.  We are on Umbraco 4.9.1

     

    @using umbraco.MacroEngines
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @*BUGGY IN IE - V2 IS HERE BUT AM CURRENTLY USING 1.8*@
    @*USING FLEX SLIDER*@
      @{
       string node = @PageData[0];
       if(!String.IsNullOrWhiteSpace(node)){
       var mediaFolder = Library.MediaById(node); 
                   <div class="generalMediaContainer">
                    <div class="generalFlexslider-container">
                    <div class="generalFlexslider">
                    <ul class="slides">
            @foreach(dynamic slideImage in mediaFolder.Children){
            if(slideImage.imageName.GetType() != typeof(umbraco.MacroEngines.DynamicXml))
              {
                  var slideCaption = @slideImage.caption.ToString();
                       <li>
                        <img src="/imagegen.ashx?width=500&[email protected]" title="@slideImage.caption" alt="@slideImage.altTag" data-caption="#@slideImage.Id"  />
                        @*<img src="@slideImage.umbracoFile" title="@slideImage.caption" alt="@slideImage.altTag" data-caption="#@slideImage.Id" />*@
    
    
    
    
                 @if(!String.IsNullOrEmpty(@slideCaption)){
                         <p class="flex-caption" id="@slideImage.Id">Caption:@slideCaption</p> 
                 }else{
    
                 }
    
    
                           @*
                           @if(@slideImage.HasValue("caption")){
                                <p class="flex-caption" id="@slideImage.Id">@slideImage.caption</p> 
                            }                            
                                *@                                     
                        </li>
              }                                                
                      }
                       </ul>
                    </div>
                   </div>
        <img class="loadingImg" src="/media/119203/ajax-loader-edit.gif" />
                 </div>
        }     
      }
    
    
    
    
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 25, 2013 @ 22:27
    Tom Fulton
    1

    Hi Carlos,

    Not sure what's causing that - could be a legacy Razor bug.  One quick way around it would be to use Model.GetPropertyValue("prop") to access your properties instead of using the "dynamic" way.  The first way will always return a string and skips any model binding to DynamicXml or otherwise

    So something like:

    var slideCaption = @slideImage.GetPropertyValue("caption");

    Hope this helps,
    Tom 

     

  • Wouter Dewispelaere 5 posts 47 karma points
    Mar 25, 2013 @ 22:27
    Wouter Dewispelaere
    1

    Hi Carlos,

    We have encountered the same issue as well.

    In Umbraco 4.11.5 following check helped (instead of using isNullOrEmpty(@slideCaption)):

     @if(!String.IsNullOrEmpty(slideImage.getProperty("caption").value.toString())){

    Kind regards,

    WD

  • Carlos 338 posts 472 karma points
    Mar 25, 2013 @ 22:29
    Carlos
    100

    Yeh we found a fix. Just found it and haven't posted it yet.  Our fix is.  Mainly it was the caption part bugging us. So we wrapped it in this.  Hope it helps someone else.

    @if(slideImage.caption.GetType() != typeof(umbraco.MacroEngines.DynamicXml))
              {
      <p class="flex-caption" id="@slideImage.Id">@slideImage.GetProperty("caption")</p> 
      }
  • Jesper Haug Karsrud 15 posts 77 karma points
    Mar 26, 2013 @ 09:32
    Jesper Haug Karsrud
    0

    Wouldn't using @slideImage.GetPropertyValue("caption") make more sense? If I remember correctly, you wouldn't get any output if it's empty, so you could do a normal !string.IsNullOrEmpty() to check if it has a value. I know you've managed to work around the problem using type checking, just wanted to make another suggestion :)

  • gary 385 posts 916 karma points
    Mar 26, 2013 @ 10:41
    gary
    0

    Hi All

    This is more a question than maybe adding something, but

    where does "hasValue" fit within this?

    Is it not an easier check than stringNullOrEmpty, ie not converting to string to check?

    As I said, I dont know that it can work here as I do not use webforms razor, but MVC style something like

    @if { slideImage.hasValue("caption") <p> . . . . } else{} or something similar should produce the desired check.

    The reason I ask is beacuse in this instance, if there is no caption, you may want to do something different with the image, or the div for the caption, understand that if it's blank it displays nothing, however a "check" may still be useful.

    Even if we can rule it out, it would be useful to know why it doesn't work here and therefore in other similar examples.

    Regards G

  • Carlos 338 posts 472 karma points
    Mar 26, 2013 @ 16:05
    Carlos
    0

    @Gary,

    I actually did that check. The issue was actually the first part of the check

    @if(slideImage.caption.GetType()!=typeof(umbraco.MacroEngines.DynamicXml))

    I actually tried the  .HasValue().  The issue was, the .hasValue was not picking up whether the textbox was empty.  Not sure why, but my original check was to have .HasValue() BUT it still acted as if there was a value or text in the textbox, BUT it was not.  I have a feeling it was because of the way we are pulling our dynamic nodes passing in a variable, (in the original example above).

    @Jesper,  The .getPropertyValue does work in the case of where the property was not wrapped in a <p> tag.  The value spits out but the paragraph tag still shows up in the markup.  The same issue we has using the .HasValue() happened when I tried to use the IsNullOrEmpty(). It was not actually doing the check and it still thought there was a value in the text box, even though there was absolutely no text, whitespace, etc within the box.  That is why the @if statement above worked in our case.  I have a feeling that if we were getting a basic property checking @Model, we would have gotten the desired affect, BUT since we were passing in a dynamic node, in our case we had to use the .GetType() and typeof() check.

    Believe me, I tried just about any way I could to get the desired affect for nearly 2 hours trying many combinations. GetProperty and GetPropertyValue worked to output the property, but since the property was in a <p> tag with a styled class added to it, it made more sense to use our solution.

    Thanks for the feedback and suggestions. We may go back and look at this again, but for now that was our solution above.


  • Carlos 338 posts 472 karma points
    Dec 06, 2013 @ 20:02
    Carlos
    0

    On Umbraco 4.11. using Razor.

    My problem is back,  When using a Multiline textblock for a property on the image MediaType I have a check to see if it is empty.

    My check to see if it is empty 

     

    I am using

    var mediaFolder = Library.MediaById(node); 
    @foreach(dynamic slideImage in mediaFolder.Children){
    @if(@slideImage.caption.ToString() != String.Empty){
    @slideImage.caption
    }else{Property Empty}

     

    I tried using 

    @if(!String.IsNullOrWhiteSpace(@slideImage.caption.ToString()))

    That did not work either.

     

    The "caption" property is on the image Media Type.  For some reason if the property is empty, it is not going into the ELSE statement.

    The image URL is coming through fine, it is just this property that is causing issues with not finding out if it is Empty or not. 

    Not sure what the issue is. Any help is appreciated... again.

Please Sign in or register to post replies

Write your reply to:

Draft