If I now try to run the same razor code as above I get this error: "umbraco.MacroEngines.DynamicXml' does not contain a definition for 'url'". If I do a quickwacth on (Model.projectUrls.item).BaseElement again I get this:
So if only 1 item is available the root node is removed again and the "d" value from the razor loop becomes the url element and thus I can't even reach the title element anymore in my loop. This is a serious problem and probably a bug.
You sample probably works, but as I already said here I think this is too complicated and it should be easier. I think this is a bug and that's why I created the workitem.
Probably because the element returned in the foreach is <data> which is a single element and removed. The subelement is item which now works with 1 and more elements. Maybe I've got something here ;-).
hy everybody longtime abstinence but now i'm back with a little bit of time and useful tips. during the last weeks and intense work with asp mvc3 in relation with razor, i discovered a lot of interesting stuff. The problem is not the removed root node. The logic behind is the dynamic node context, so if there are different values inside the element it will be casted as an dynamicxml e.g. node. So you have to understand the logic behind.
I will show you an example tomorrow to understand what i mean. it's some troubleshooting and thinking behind to realize the nature of razor and the great abilities.
So long and good evening to the rest of the community.
Root node removed problem in DynamicXml
Hello,
In some situations I've got a problem if the root node is removed from DynamicXml. Here is an example where I use the Embedded Content package:
The xml from umbraco.config:
The razor code:
This code works if the item element is available 2 times. If I do a quickwatch on (Model.projectUrls.item).BaseElement I get this:
Now if I remove an item this becomes my xml from umbraco.config
If I now try to run the same razor code as above I get this error: "umbraco.MacroEngines.DynamicXml' does not contain a definition for 'url'". If I do a quickwacth on (Model.projectUrls.item).BaseElement again I get this:
So if only 1 item is available the root node is removed again and the "d" value from the razor loop becomes the url element and thus I can't even reach the title element anymore in my loop. This is a serious problem and probably a bug.
Jeroen
I've also created a workitem for this: http://umbraco.codeplex.com/workitem/30291
Jeroen
Hi Jeroen,
I think this is the same problem that is detailed in the topic
http://our.umbraco.org/forum/developers/razor/18859-Question-for-an-XML-Data-Loop?p=1
In the end we ended up having to check the Base Element within the foreach loop
So I think your code would end up something like this
Hope that helps
Alex
Hello Alex,
You sample probably works, but as I already said here I think this is too complicated and it should be easier. I think this is a bug and that's why I created the workitem.
Jeroen
The easiest solution would to never remove the root node. I don't understand why the root node is removed anyway.
Jeroen
Yes I agree, in fact I think I said the same in last post on the original topic I posted the link too.
Hopefully the workitem you created will draw some attention to it.
Hmm I just discoverd that this also works with both 1 item and 2 items:
Probably because the element returned in the foreach is <data> which is a single element and removed. The subelement is item which now works with 1 and more elements. Maybe I've got something here ;-).
Jeroen
hy everybody longtime abstinence but now i'm back with a little bit of time and useful tips. during the last weeks and intense work with asp mvc3 in relation with razor, i discovered a lot of interesting stuff. The problem is not the removed root node. The logic behind is the dynamic node context, so if there are different values inside the element it will be casted as an dynamicxml e.g. node. So you have to understand the logic behind.
I will show you an example tomorrow to understand what i mean. it's some troubleshooting and thinking behind to realize the nature of razor and the great abilities.
So long and good evening to the rest of the community.
Hello,
I've had a little twitter chat with Gareth Evans:
http://twitter.com/#!/agrath/status/66336778604392449
http://twitter.com/#!/agrath/status/66337301172731904
http://twitter.com/#!/jbreuer1985/status/66401566307000320
http://twitter.com/#!/agrath/status/66402360137760768
http://twitter.com/#!/jbreuer1985/status/66405120178528256
So he will fix it in Umbraco 4.7.1 :-D.
Jeroen
is working on a reply...