Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hey,
I'm trying to output some content from my nested content item.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using Umbraco.Web.Models var anchors = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("anchor"); <ul> foreach(var anchor in anchors) { <li><a href="#">@anchor.GetPropertyValue<String>("anchor")))</a></li> } </ul>
But i'm getting an error saying that the render model doesn't has "GetPropertyValue" ?
Hi Thomas It was great to meet you in person at CodeGarden.
I think you might be missing this reference
@using Umbraco.Web
Try adding that at the top.
Cheers
Paul
Hi Paul.
Likewise ! :), thanks for the snaps shot.
I tried to add that, but it's not changing anything.
// Thomas
Hey Thomas,
The issue is the point at which you are calling GetPropertyValue.
Based on the code above, your view is inheriting from UmbracoTemplatePage.
So, in this scenario, you need to change your third line from:
var anchors = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("anchor");
to
var anchors = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("anchor");
Alternatively, you can change your 1st line from:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@inherits Umbraco.Web.Mvc.UmbracoViewPage
UmbracoTemplatePage wraps your actual Model in a Render Model, so it's exposed via the Model.Content property, where as UmbracoViewPage doesn't.
UmbracoTemplatePage
Model.Content
UmbracoViewPage
It's becoming considered best practice to use UmbracoViewPage instead of UmbracoTemplatePage so I'd switch to that if I were you :-)
Thanks,
Nik
Well spotted @nik
@thomas I used Nested Content in my starter kit for the Main Carousel.
I put the carousel in a partial view. Here is a link to that partial view, maybe it will help with any other things which come up.
https://github.com/prjseal/CodeShareUmbracoStarterKit/blob/master/src/CSUSK.Web/Views/Partials/Content/_MainCarousel.cshtml
Hey, Thanks guys.
I have tried this. But are still getting the same issue.
@inherits UmbracoViewPage @using Umbraco.Web.Models var anchors = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("anchor"); <ul> foreach(var item in anchors) { <li><a href="">@item.GetPropertyValue<string>("anchor")</a></li> } </ul>
I also tried.
@inherits UmbracoViewPage @using Umbraco.Web.Models IEnumerable<IPublishedContent> anchors = Umbraco.AssignedContentItem.GetPropertyValue<IEnumerable<IPublishedContent>>("anchor"); <ul> foreach (IPublishedContent item in anchors ) { item.GetPropertyValue<string>("anchor") }
Still same issue.. ?
Hi Thomas,
That seems odd. Both of those fundamentally look like they should work.
Are you sure the error is still being thrown in the same view and not now being thrown in a different one?
The top option is the one that I would go for rather than the second one.
I'm creating an grid item with the Doc type grid editor. Does that make any changes ?
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Nested Content GetPropertyValue
Hey,
I'm trying to output some content from my nested content item.
But i'm getting an error saying that the render model doesn't has "GetPropertyValue" ?
Hi Thomas It was great to meet you in person at CodeGarden.
I think you might be missing this reference
Try adding that at the top.
Cheers
Paul
Hi Paul.
Likewise ! :), thanks for the snaps shot.
I tried to add that, but it's not changing anything.
// Thomas
Hey Thomas,
The issue is the point at which you are calling GetPropertyValue.
Based on the code above, your view is inheriting from UmbracoTemplatePage.
So, in this scenario, you need to change your third line from:
to
Alternatively, you can change your 1st line from:
to
UmbracoTemplatePage
wraps your actual Model in a Render Model, so it's exposed via theModel.Content
property, where asUmbracoViewPage
doesn't.It's becoming considered best practice to use
UmbracoViewPage
instead ofUmbracoTemplatePage
so I'd switch to that if I were you :-)Thanks,
Nik
Well spotted @nik
@thomas I used Nested Content in my starter kit for the Main Carousel.
I put the carousel in a partial view. Here is a link to that partial view, maybe it will help with any other things which come up.
https://github.com/prjseal/CodeShareUmbracoStarterKit/blob/master/src/CSUSK.Web/Views/Partials/Content/_MainCarousel.cshtml
Cheers
Paul
Hey, Thanks guys.
I have tried this. But are still getting the same issue.
I also tried.
Still same issue.. ?
Hi Thomas,
That seems odd. Both of those fundamentally look like they should work.
Are you sure the error is still being thrown in the same view and not now being thrown in a different one?
The top option is the one that I would go for rather than the second one.
Nik
I'm creating an grid item with the Doc type grid editor. Does that make any changes ?
is working on a reply...