Copied to clipboard

Flag this post as spam?

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


  • Mikkel Johansen 116 posts 292 karma points
    Sep 22, 2011 @ 09:51
    Mikkel Johansen
    1

    Empty textstring properties on Medianode/type - v. 4.7.1

    Umbraco 4.7.1

    I have this MediaType with several textstring properties.

    In version 4.7 I could do the following to get the value of the property (eg. phone).

    dynamic person = Model.MediaById(1234);
    @person.phone

    If "phone" is empty, the result is an empty string.

    In the new version 4.7.1 I have big trouble with these empty properties. And I need to write a bit more code to get the content.

    var person = Model.MediaById(1234);
    @person.GetProperty("phone").Value

    The result if "phone" is empty, is "<phone></phone>". But if it is not empty, then result is eg. "12345678" (NOT <phone>12345678</phone>)

    Am I doing something wrong or could it be a bug in the Razor engine in 4.7.1 ?

    Thanks
    Mikkel

  • Mr A 216 posts 278 karma points
    Sep 22, 2011 @ 17:13
    Mr A
    0
    dynamic person = Model.MediaById(1234);
     @person.phone

    I tried the above code , it works fine Umbraco 4.7.1

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Sep 22, 2011 @ 21:09
    Dan Diplo
    0

    I can confirm this - a colleague was having the same propblem today. Empty custom properties come back as type DynamicXml rather than (as I would expect) an empty string, null or perhaps DynamicNull.

    Steps to reproduce:

    Go to Settings > Media Types in Umbraco 4.7.1 back-office. Add a custom TextString property to the Image media type with an alias of AlternativeText. Create an image in the Media folder and leave the AlternativeText field empty. Make a note of the id of the image. Then run this Razor snippet:

    var image = Library.MediaById(1055);
    
    <p>
    @image.AlternativeText.GetType()
    </p>

    This returns umbraco.MacroEngines.DynamicXml

    This isn't what I would expect and can cause problems when testing for a value which you would expect to be a string. I believe it does the same for other empty datatypes (not just TextString), which also return DynamicXml as the type.

    I have done my bit and raised this as Workitem 3054 on Codeplex 

  • Mikkel Johansen 116 posts 292 karma points
    Sep 22, 2011 @ 22:53
    Mikkel Johansen
    1

    @Dan: Thanks for the help. I have voted on the Workitem on Codeplex, let's hope other do it aswell.

  • Mikkel Johansen 116 posts 292 karma points
    Sep 23, 2011 @ 13:04
    Mikkel Johansen
    0

    It looks like it is the same problem in 4.7. And also in XLST.

    If I do a <xsl:copy> of the media node. I would expect the following

    <person>
    <phone></phone>
    <email>[email protected]</email>
    </person>

    But instead I get something like this

    <person>
    <phone>
    <email>[email protected]</email>
    </phone>
    </person>

    I have not tested it so much yet. Hope to get som time in the next couple of days

  • Mikkel Johansen 116 posts 292 karma points
    Jul 18, 2012 @ 00:46
    Mikkel Johansen
    0

    According to Codeplex the bug #30504 has been fixed in 4.7.1. But to me it looks like the bug has returned in 4.7.2.

    http://umbraco.codeplex.com/workitem/30847 

    Please go vote so it maybe could be fixed in 4.9 

  • psiho 101 posts 96 karma points
    Aug 09, 2012 @ 16:06
    psiho
    0

    I also ran into problems with this issue #30847, but is there any workarround? How to check if empty DynamicXml "<phone></phone>" is returned?

  • Mikkel Johansen 116 posts 292 karma points
    Aug 09, 2012 @ 22:10
    Mikkel Johansen
    0

    I am doing it by checking on "<phone></phone>".

    But it would be very nice to do a check on ""

    I have not yet tried if the "feature" is in 4.8

  • Ravi Motha 290 posts 500 karma points MVP 8x c-trib
    Aug 14, 2012 @ 13:37
    Ravi Motha
    0

    if you are using razor you can get round this via the has value  helper

    in fact I used it to counter a similar problem 

    var ageGroupTitle = @AgeGroup.HasValue("PageTitle") ? @AgeGroup.PageTitle : @AgeGroup.Name; 

     

    Ravi

  • Mikkel Johansen 116 posts 292 karma points
    Aug 16, 2012 @ 22:35
    Mikkel Johansen
    0

    @Ravi Motha sounds like a great work-around. I will try it next time.

  • psiho 101 posts 96 karma points
    Apr 26, 2013 @ 12:08
    psiho
    0

    I have the same problem with 4.11.6, at least with Media Types and textstring properties.

  • Mikkel Johansen 116 posts 292 karma points
    Apr 26, 2013 @ 23:46
    Mikkel Johansen
    0

    @psiho please go vote for the bug http://issues.umbraco.org/issue/U4-579 so it can be fixed.

Please Sign in or register to post replies

Write your reply to:

Draft