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.
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).
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.
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
I tried the above code , it works fine Umbraco 4.7.1
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:
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
@Dan: Thanks for the help. I have voted on the Workitem on Codeplex, let's hope other do it aswell.
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
But instead I get something like this
I have not tested it so much yet. Hope to get som time in the next couple of days
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
I also ran into problems with this issue #30847, but is there any workarround? How to check if empty DynamicXml "<phone></phone>" is returned?
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
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
@Ravi Motha sounds like a great work-around. I will try it next time.
I have the same problem with 4.11.6, at least with Media Types and textstring properties.
@psiho please go vote for the bug http://issues.umbraco.org/issue/U4-579 so it can be fixed.
is working on a reply...
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.