I am new to Umbraco and just building my first website using v7.12.4
I have become stuck trying to display nested content in my template. I have tried following the documentation here:https://our.umbraco.com/Documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Nested-Content
However I am getting the following error:
Compiler Error Message: CS1928: 'Umbraco.Web.Models.PartialViewMacroModel' does not contain a definition for 'GetPropertyValue' and the best extension method overload 'Umbraco.Web.PublishedContentExtensions.GetPropertyValue<T>(Umbraco.Core.Models.IPublishedContent, string)' has some invalid arguments
Please see below an image of my document type
I have placed my code in a Partial View Macro File (I hope this is right) and can be seen here:
@using Umbraco.Web
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
var items = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("ideaLinks");
foreach(var item in items)
{
<h3>@item.GetPropertyValue("title")</h3>
@Umbraco.Field(item, "method")
}
}
Can anyone see where I may be going wrong?
I have scoured the net for a solution, but to no avail - it must be something simple!
You don't have to place your code in a Partial View Macro File. You can put it in your document types template instead, or if you prefer a partial, a Partial View.
You need to inherit from UmbracoViewPage, to have the IPublishedContent in Model.
Also, I would advise against using @Umbraco.Field() for getting properties. Use Model.GetPropertyValue(), or ModelsBuilder.
Displaying Nested content
Hi,
I am new to Umbraco and just building my first website using v7.12.4
I have become stuck trying to display nested content in my template. I have tried following the documentation here:https://our.umbraco.com/Documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Nested-Content
However I am getting the following error:
Please see below an image of my document type
I have placed my code in a Partial View Macro File (I hope this is right) and can be seen here:
Can anyone see where I may be going wrong?
I have scoured the net for a solution, but to no avail - it must be something simple!
Thanks!
Sarah
Hi Sarah
You don't have to place your code in a Partial View Macro File. You can put it in your document types template instead, or if you prefer a partial, a Partial View.
You need to inherit from
UmbracoViewPage
, to have theIPublishedContent
inModel
.Also, I would advise against using
@Umbraco.Field()
for getting properties. UseModel.GetPropertyValue()
, orModelsBuilder
.Hey Søren,
Thanks so much for the quick reply - I've put the code in a Partial View (i didn't know about those!) and added the inherits and it works!
Thanks again!
This forum is invaluable :)
Sarah
is working on a reply...