'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'Image
I'm using DAMP 2.0 and for some reason, I get the above error with this simple script:
@{ if (Model.HasValue("photos")) { dynamic mediaItems = Model.photos.mediaItem; if (mediaItems.Count() != 0) { <ul> @foreach (var item in mediaItems) { var image = item.Image; <li> Original image: <a href="@image.umbracoFile">@image.nodeName</a> (@image.umbracoBytes bytes)<br />
</li> } </ul> } } }
What's confusing me is I have the Cultiv 1.5 sample site installed (both above and it use 4.7.1) and it works fine! So I'm surmising it's a configuration issue, but what?
Please also post a snippet from your umbraco.config where the damp items are stored so we can have a look at what might be wrong there.
Things I can think of right now: - Damp is not configured to store the full media xml in the umbraco.config - The property on your documentType isn't called "photos" but something else (although, then you probably wouldn't get that far anyway)
Oh man, that blows! I have a ton of XSLT's I never updated for this site... So in order to get Razor to work reliably I need to update the new XML schema?
v5 will have a new Model, you will be able to leverage your newfound Razor knowledge very well in v5, but don't expect your script to work exactly the same. It's a good learning experience, for sure. Depends on how much you are willing to invest at the moment. :-)
'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'Image
I'm using DAMP 2.0 and for some reason, I get the above error with this simple script:
@{
if (Model.HasValue("photos")) {
dynamic mediaItems = Model.photos.mediaItem;
if (mediaItems.Count() != 0)
{
<ul>
@foreach (var item in mediaItems)
{
var image = item.Image;
<li>
Original image: <a href="@image.umbracoFile">@image.nodeName</a> (@image.umbracoBytes bytes)<br />
</li>
}
</ul>
}
}
}
What's confusing me is I have the Cultiv 1.5 sample site installed (both above and it use 4.7.1) and it works fine! So I'm surmising it's a configuration issue, but what?
Your code seems fine. Maybe you can try the DAMP 2.0 Samples package to see if that works.
Jeroen
Please also post a snippet from your umbraco.config where the damp items are stored so we can have a look at what might be wrong there.
Things I can think of right now:
- Damp is not configured to store the full media xml in the umbraco.config
- The property on your documentType isn't called "photos" but something else (although, then you probably wouldn't get that far anyway)
This isn't from the umbraco.config, but if I use the ".ToHtml()" method on mediaItems, this is what I get:
<root><mediaitem><node id="5507" version="feae5c3e-5438-4f78-8673-b76f6d410098" parentid="5506" level="3" writerid="0" nodetype="1032" template="0" sortorder="1" createdate="2011-12-16T10:16:12" updatedate="2011-12-16T10:16:13" nodename="IMG_1845" urlname="img_1845" writername="Administrator" nodetypealias="Image" path="-1,5505,5506,5507"><data alias="umbracoFile">/media/90927/img_1845.jpg</data><data alias="umbracoWidth">1728</data><data alias="umbracoHeight">1296</data><data alias="umbracoBytes">560754</data><data alias="umbracoExtension">jpg</data><data alias="caption"></data></node></mediaitem></root>
Does that help?
And if I call .ToXml() on each item in the foreach loop I get this:
<mediaItem><node id="5507" version="feae5c3e-5438-4f78-8673-b76f6d410098" parentID="5506" level="3" writerID="0" nodeType="1032" template="0" sortOrder="1" createDate="2011-12-16T10:16:12" updateDate="2011-12-16T10:16:13" nodeName="IMG_1845" urlName="img_1845" writerName="Administrator" nodeTypeAlias="Image" path="-1,5505,5506,5507"><data alias="umbracoFile">/media/90927/img_1845.jpg</data><data alias="umbracoWidth">1728</data><data alias="umbracoHeight">1296</data><data alias="umbracoBytes">560754</data><data alias="umbracoExtension">jpg</data><data alias="caption" /></node></mediaItem>
So, yeah, I'm really stumped!
I'm wondering, is it because I'm using the legacy XML schema?
Not sure. What happens if you change item.Image to item.node ?
Aaah legacy schema, that explains the weirdly named "node" node..!
Oh boy.. good luck with that. ;-) I'm not sure most of the Razor stuff works with the legacy schema to be honest.
Oh man, that blows! I have a ton of XSLT's I never updated for this site... So in order to get Razor to work reliably I need to update the new XML schema?
Well, if I have to I have to I guess...
Or... I could replace all the XSLT's with Razor scripts instead... Would that put me ahead of the game for 5.0?
I am really not certain about it, but I've never met anybody who used the legacy schema with Razor. You're a brave man indeed! ;-)
Make sure to create a good backup and then read these instructions: http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/switching-between-old-and-new-schema
Also, for a semi-automatic conversion of your existing XSLT, have a look here (where it says "Optional: upgrade your xslt files to the 4.5 schema"): http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/switching-between-old-and-new-schema
v5 will have a new Model, you will be able to leverage your newfound Razor knowledge very well in v5, but don't expect your script to work exactly the same. It's a good learning experience, for sure. Depends on how much you are willing to invest at the moment. :-)
Hmm I think Razor won't work very well with the legacy schema so it's best to update to the new schema. You can try to update all your old xslt files with this: http://our.umbraco.org/projects/developer-tools/xsltupdater-for-umbraco.
Jeroen
is working on a reply...