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
Hi,
Can anyone out there please help; I've been trying to get the media picker image to show on the front end for 2 days now, but I keep getting an error message, I've tried everything and don't know exactly what I'm doing wrong.
See my code below.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ Layout = null; var Current = CurrentPage; } <div class="img-accordion"> <ul> @{ var accordion = Current.GetPropertyValue<IEnumerable<IPublishedContent>>("nestedContent"); foreach (var item in accordion) { <li> <div> <a href="#"> <img src='@Umbraco.Media(@item.GetPropertyValue("accordionIcon")).Url'> <span class="overlay"> <h3>@Umbraco.Field(item, "accordionTextField")</h3> <p>@Umbraco.Field(item, "accordionTextareaField")</p> </span> </a> </div> </li> } } </ul> </div>
and below is the error I keep getting.
Note: I am working with Dynamic content, when I switch to strongly typed (@inherits Umbraco.Web.Mvc.UmbracoViewPage), everything seems to be working.
@inherits Umbraco.Web.Mvc.UmbracoViewPage
The question would be how to render the Media Picker using Dynamic (@inherits Umbraco.Web.Mvc.UmbracoTemplatePage) ?
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
Thanks
Hi Elin
Do not use dynamics! Please, read "Common Pitfalls" - https://our.umbraco.org/documentation/reference/Common-Pitfalls/
What is the "Current" variable in your example?
var accordion = Current.GetPropertyValue<IEnumerable<IPublishedContent>>("nestedContent");
Thanks,
Alex
Hi Alex,
Thanks for sharing this link with me, I'll try to avoid using dynamics next time.
To answer your question, Current refers to the current page var Current = CurrentPage;
var Current = CurrentPage;
I updated my original post, somehow I missed adding it.
Thanks.
Elin
This code should work:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ Layout = null; } <div class="img-accordion"> <ul> @{ var accordion = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("nestedContent"); foreach (var item in accordion) { <li> <div> <a href="#"> @if (item.HasValue("accordionIcon")) { var image = item.GetPropertyValue<IPublishedContent>("accordionIcon"); <img src='@image.Url'> } <span class="overlay"> <h3>@Umbraco.Field(item, "accordionTextField")</h3> <p>@Umbraco.Field(item, "accordionTextareaField")</p> </span> </a> </div> </li> } } </ul> </div>
Thanks, Alex
I tried your code, but I get an error message, see the screenshot below.
Hi Elin,
Try this one:
var imageId = item.GetPropertyValue<int>("accordionIcon"); var image = Umbraco.TypedMedia(imageId); if(image != null) { <img src='@image.Url'> }
I got another error with the new code you provided.
And this is the same error that I've been having trouble with, it keeps telling me that
ImageAccordion does not contain a definition for "GetPropertyValue"
I really don't know what to do anymore, I guess this just won' work for some reason.
can you:
var image = Model.Content.GetPropertyValue<IPublishedContent>("accordionIcon"); if (image != null) { <img src="@image.Url" alt="@image.Name" /> }
??
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
How to Render Nested Content Media Picker
Hi,
Can anyone out there please help; I've been trying to get the media picker image to show on the front end for 2 days now, but I keep getting an error message, I've tried everything and don't know exactly what I'm doing wrong.
See my code below.
and below is the error I keep getting.
Note: I am working with Dynamic content, when I switch to strongly typed (
@inherits Umbraco.Web.Mvc.UmbracoViewPage
), everything seems to be working.The question would be how to render the Media Picker using Dynamic (
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
) ?Thanks
Hi Elin
Do not use dynamics! Please, read "Common Pitfalls" - https://our.umbraco.org/documentation/reference/Common-Pitfalls/
What is the "Current" variable in your example?
Thanks,
Alex
Hi Alex,
Thanks for sharing this link with me, I'll try to avoid using dynamics next time.
To answer your question, Current refers to the current page
var Current = CurrentPage;
I updated my original post, somehow I missed adding it.
Thanks.
Elin
This code should work:
Thanks, Alex
Hi Alex,
I tried your code, but I get an error message, see the screenshot below.
Thanks,
Elin
Hi Elin,
Try this one:
Hi Alex,
I got another error with the new code you provided.
And this is the same error that I've been having trouble with, it keeps telling me that
I really don't know what to do anymore, I guess this just won' work for some reason.
Thanks,
Elin
can you:
??
is working on a reply...