Hi Michael. You should'nt use the ContentService to get content, since it queries the database instead of the content cache, which is not good for performance. Also it returns a IContent, which you mentioned. The ContentService should only be used for create/edit/delete operations.
Instead, use the UmbracoHelper methods go fetch content, which returns a IPublishedContent, which you should be able to cast as a ContentModel.
To use the Umbraco helper, simply type @Umbraco.TypedContent(1063) to get your content.
Cast to Definit Object
I have a Master Template . In this a defined the heder and the Footer.
The Footer and the Header are Content.
This is my Master Template:
Now My Problem is. How I Get the Property from the Header. I loade the Header With
But Help is From IContect. And I need ContentModels.Header. How I can Cast this or get ContentModels.Header.
Hi Michael. You should'nt use the ContentService to get content, since it queries the database instead of the content cache, which is not good for performance. Also it returns a IContent, which you mentioned. The ContentService should only be used for create/edit/delete operations.
Instead, use the UmbracoHelper methods go fetch content, which returns a IPublishedContent, which you should be able to cast as a ContentModel.
To use the Umbraco helper, simply type @Umbraco.TypedContent(1063) to get your content.
Hope this was helpful! / Dennis
Hi guys,
Is it right that ContentModels.Header is Models Builders class?
Just want to add to Dennis' post that you can cast IPublishedContent object to ContentModels.Header just usual casting in c#
Thanks,
Alex
thank you for the Help
You are welcome, Michael
Write more questions, have a nice evening!
is working on a reply...