I feel stupid - even after about an hour googeling I didn't find a solution to get access to my custom properties.
My code is this:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
var selection = Umbraco.Content(1073).Children.Where(x => x.IsVisible()).ToArray();
foreach (var item in selection){
<a href="@item.Url">@item.preis</a>
}
}
But all I get is "'IPublishedContent' does not contain a definition for 'preis' and no accessible extension method 'preis' accepting a first argument of type 'IPublishedContent' could be found"
Umbraco.Content(xxx) always returns an strongly typed IPublishedContent that you have to cast to the desired DocumentType - Type (aka the name of the document type).
My DocumentType is called "About", so instead of doing
foreach (var item in selection){
I have to do
foreach (About item in selection){
an now I can access "item.Preis".
Another pitfall: The names in the backend are lowercase (i.e. "preis") but if you use them in code you have to go uppercase -> "Preis".
I hope I got this all correct? Happy for help if I'm wrong!
Access custom property in Partial View Marco?
Hello,
I feel stupid - even after about an hour googeling I didn't find a solution to get access to my custom properties.
My code is this:
But all I get is "'IPublishedContent' does not contain a definition for 'preis' and no accessible extension method 'preis' accepting a first argument of type 'IPublishedContent' could be found"
How do I get access to my custom properties?
Thanx, Arnim.
Aww ... right in front of my eyes ... shame on me ...
Its just
Solved. 🙄
Now I really got it ... I guess?
Umbraco.Content(xxx) always returns an strongly typed IPublishedContent that you have to cast to the desired DocumentType - Type (aka the name of the document type).
My DocumentType is called "About", so instead of doing
I have to do
an now I can access "item.Preis".
Another pitfall: The names in the backend are lowercase (i.e. "preis") but if you use them in code you have to go uppercase -> "Preis".
I hope I got this all correct? Happy for help if I'm wrong!
is working on a reply...