I'm guessing this is something super simple, but I've hit a dead end.
I am trying to render a MultiNode Treepicker2 datatype in a partial to reuse on multiple pages throughout my site.
If I have the properties in a in single document type, and only use it on that template, this works as expected:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using Umbraco.Web.Models;
@{
var typedMultiNodeTreePicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("tenYearsArticle");
foreach (var item in typedMultiNodeTreePicker)
{
<p class="sidebar-ten-years-entry-title"><a href="@item.Url">@item.Name</a></p>
}
}
but if I try to move those properties in a stand-alone content type to reuse in a partial across the site, this doesn't work:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
@using Umbraco.Web
@using Umbraco.Web.Models;
@{
var tenyears = Umbraco.TypedContent(1687).Children("tenYearsAgoThisWeek");
var typedMultiNodeTreePicker = tenyears.GetPropertyValue<IEnumerable<IPublishedContent>>("tenYearsArticle");
foreach (var item in typedMultiNodeTreePicker)
{
}
}
this gives the
error:
System.Collections.Generic.IEnumerable<Umbraco.Core.Models.IPublishedContent>' 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
It seems like it should work, I'm misunderstanding something fundamental about how IPublishedContent works. Thank you
Multinode Treepicker 2 in partial
I'm guessing this is something super simple, but I've hit a dead end.
I am trying to render a MultiNode Treepicker2 datatype in a partial to reuse on multiple pages throughout my site.
If I have the properties in a in single document type, and only use it on that template, this works as expected:
but if I try to move those properties in a stand-alone content type to reuse in a partial across the site, this doesn't work:
this gives the error:
System.Collections.Generic.IEnumerable<Umbraco.Core.Models.IPublishedContent>' 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
It seems like it should work, I'm misunderstanding something fundamental about how IPublishedContent works. Thank you
Hi Shawn,
You are trying to call a method that does not exist - tenyears is a list of children, not publishedcontent.
You either need to iterate (foreach) the "tenyears"-list, or pick the first child
It worked - that totally makes sense - thank you very much for taking the time!
is working on a reply...