I'm creating a Razor macro to generate an RSS feed for the NewsItems on my site.
The macro is generating a compilation error CS1061: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'photoProvider'. Commenting the appropriate line out and the macro works just fine.
Here's what I'm doing:
var root = Model.Content.AncestorOrSelf();
var nodes = root.Descendants("NewsItem").Take(20);
## some RSS stuff here ###
foreach (var item in nodes) {
<item>
### RSS item stuff here ###
@if(item.HasValue("photoProvider")) {
<media:credit scheme="urn:ebu">Photo provided by: @item.photoProvider</media:credit>
}
</item>
}
All the other @item.somethings work fine as expected (not shown here) and I've double-checked I've got the property name correct... I've spent too long trying to make this work... any help would be appreciated!
You can use syntax like .propertyAlias only if "item" is dynamic, and it's not the good way to do it. Look into strongly typed approach and Models builder if you want to avoid using "GetPropertyValue" method.
Compilation error in macro - help!
Hi All,
I'm creating a Razor macro to generate an RSS feed for the
NewsItem
s on my site.The macro is generating a compilation error CS1061: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'photoProvider'. Commenting the appropriate line out and the macro works just fine.
Here's what I'm doing:
All the other
@item.somethings
work fine as expected (not shown here) and I've double-checked I've got the property name correct... I've spent too long trying to make this work... any help would be appreciated!Hi James
You have to use "GetPropertyValue" method for accessing property values:
You can use syntax like .propertyAlias only if "item" is dynamic, and it's not the good way to do it. Look into strongly typed approach and Models builder if you want to avoid using "GetPropertyValue" method.
https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Umbraco.ModelsBuilder
Hope it make sense for you.
Thanks,
Alex
Many thanks, Alex.
I'm a PHP guy and Umbraco is all a bit voodoo to me :)
You are welcome, James!
Write if some questions!
/Alex
is working on a reply...