Input string was not in a correct format - accessing Multi-Node Tree Picker value with razor
Hi,
I'm not sure whether this is linked to the razor support or to the Multi-node tree picker implementation.
I
have a datatype using the multi-node tree picker (MNTP) (configured for
Content, minimum node selections is 0, CSV, with XPath expression and
filter).
When I try to get the value and no node has been selected with the MNTP, accessing the value using razor syntax generates an error:
@Model.myProperty
I have to use the following workaround:
@Model.GetProperty("myProperty").Value
When at least one node is selected, I don't get any errors.
Part of the dynamic nature of the Razor implementation is that your properties will be evaluated at runtime to see if they can be cast to DynamicXml, lists, etc. When a list is just an empty string (no value), the parser can in no way determine that the values in there were supposed to be a list, so it just returns an empty string.
So eventually it's up to you to test if the property is empty, if not, do what you want with the list.
Actually that's just the point: It doesn't return an empty string - it throws an error. This is different from for example an (empty) numeric property - an empty numeric property returns an empty string.
I checked umbraco.config, the multi-node tree picker looks like this:
<myProperty><![CDATA[1104]]></myProperty>
and, when empty, like this:
<myProperty><![CDATA[]]></myProperty>
Whereas an empty numeric property does not have the CDATA in it:
You are correct! I can confirm that this is an issue that will be solved in 4.7.1, the fix has been added to the dev version, I've tested it and this problem is solved. If Codeplex worked, I would've linked to the changeset, but there is a server error at the moment.
Until 4.7.1 is released your only option is unfortunately to do GetProperty like you did.
Input string was not in a correct format - accessing Multi-Node Tree Picker value with razor
Hi,
I'm not sure whether this is linked to the razor support or to the Multi-node tree picker implementation.
I have a datatype using the multi-node tree picker (MNTP) (configured for Content, minimum node selections is 0, CSV, with XPath expression and filter).
When I try to get the value and no node has been selected with the MNTP, accessing the value using razor syntax generates an error:
@Model.myProperty
I have to use the following workaround:
@Model.GetProperty("myProperty").Value
When at least one node is selected, I don't get any errors.
Part of the dynamic nature of the Razor implementation is that your properties will be evaluated at runtime to see if they can be cast to DynamicXml, lists, etc. When a list is just an empty string (no value), the parser can in no way determine that the values in there were supposed to be a list, so it just returns an empty string.
So eventually it's up to you to test if the property is empty, if not, do what you want with the list.
Actually that's just the point: It doesn't return an empty string - it throws an error. This is different from for example an (empty) numeric property - an empty numeric property returns an empty string.
I checked umbraco.config, the multi-node tree picker looks like this:
<myProperty><![CDATA[1104]]></myProperty>
and, when empty, like this:
<myProperty><![CDATA[]]></myProperty>
Whereas an empty numeric property does not have the CDATA in it:
<myNumericProperty />
You are correct! I can confirm that this is an issue that will be solved in 4.7.1, the fix has been added to the dev version, I've tested it and this problem is solved. If Codeplex worked, I would've linked to the changeset, but there is a server error at the moment.
Until 4.7.1 is released your only option is unfortunately to do GetProperty like you did.
Currently I've got the same problem. Is there already a nightly build of 4.7.1 where this is fixed?
Jeroen
Just to confirm I solved this by grabbing the 4.7.1 nightly of umbraco.MacroEngines.dll from Codeplex.
Sorry at the moment I cannot locate the link, only 4.7.0 and 5.. it was there a week ago.. :-(
Hi, check out Sebastiaans sample site with lots of Razor code, it has also the new .dll. http://our.umbraco.org/projects/developer-tools/cultiv-razor-examples Other than that you can find the dll in the latest nighlty here http://nightly.umbraco.org/umbraco%204.7.1/4.7.1/
is working on a reply...