PublishedContentBase does not contain a definition for 'GetPropertyValue'
Hi,
I've created a multinode tree picker datatype and trying to list the the thumbnail of a vehicle as part of the foreach loop, however i keep getting the error message;
'Umbraco.Web.Models.PublishedContentBase' does not contain a definition for 'GetPropertyValue'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Umbraco.Web.Models.PublishedContentBase' does not contain a definition for 'GetPropertyValue'
Source Error:
Line 23: @if (content.HasValue("vehicleThumbnail"))
Line 24: {
Line 25: var mediaItem = Umbraco.TypedMedia(content.GetPropertyValue("vehicleThumbnail"));
Line 26: <img class="featuredVehicleImg img-responsive" src="@mediaItem.GetPropertyValue("umbracoFile")" alt="@content.Name"/>
Line 27: }
Below is the razor code;
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
Macro to list nodes from a Multinode tree picker, using the pickers default settings.
Content Values stored as xml.
To get it working with any site's data structure, simply set the selection equal to the property which has the
multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property).
*@
@* Lists each selected value from the picker as a link *@
<div class="featuredVehicles">
@foreach (var id in CurrentPage.featuredVehicles.Split(','))
{
@*For each link, get the node, and display its name and url*@
var content = Umbraco.Content(id);
<div class="col-xs-6 col-md-4 col-xs-height">
<a href="@content.Url">
@if (content.HasValue("vehicleThumbnail"))
{
var mediaItem = Umbraco.TypedMedia(content.GetPropertyValue("vehicleThumbnail"));
<img class="featuredVehicleImg img-responsive" src="@mediaItem.GetPropertyValue("umbracoFile")" alt="@content.Name"/>
}
<strong>
<span class="name">@content.Name</span>
</strong>
<span class="desc">@content.shortContent</span>
<span class="prx"><strong>@content.vehiclePrice</strong>from, per day</span>
<span class="label label-primary moreinfo">More Info</span>
</a>
</div>
}
</div>
Tried .umbracoFile and .Url but neither seems to work.
'Umbraco.Web.Models.PublishedContentBase' does not contain a definition for 'GetPropertyValue'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Umbraco.Web.Models.PublishedContentBase' does not contain a definition for 'GetPropertyValue'
Source Error:
Line 24: @if (content.HasValue("vehicleThumbnail"))
Line 25: {
Line 26: var mediaItem = Umbraco.TypedMedia(content.GetPropertyValue("vehicleThumbnail"));
Line 27: <img class="featuredVehicleImg img-responsive" src="@mediaItem.GetPropertyValue("umbracoFile")" alt="@content.Name"/>
Line 28: }
This is confusing me now. If i cannot use 'GetPropertyValue' then what can i use instead? TypedMedia?
Here is the updated code, now i'm having trouble getting the image out, it's hitting the if statement, missing that and executing the else statement;
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using Umbraco.Web
@*
Macro to list nodes from a Multinode tree picker, using the pickers default settings.
Content Values stored as xml.
To get it working with any site's data structure, simply set the selection equal to the property which has the
multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property).
*@
@* Lists each selected value from the picker as a link *@
<div class="featuredVehicles">
@foreach (var id in CurrentPage.featuredVehicles.Split(','))
{
@*For each link, get the node, and display its name and url*@
var vehicleContent = Umbraco.Content(id);
<div class="col-xs-6 col-md-4 col-xs-height">
<a href="@vehicleContent.Url">
@if (vehicleContent.HasValue("vehicleThumbnail"))
{
var mediaItem = Umbraco.TypedMedia(vehicleContent.GetPropertyValue("vehicleThumbnail"));
<img class="featuredVehicleImg img-responsive" src="@vehicleContent.GetPropertyValue("umbracoFile")" alt="@vehicleContent.Name"/>
}
else
{
<img class="comingSoon" src="http://placehold.it/650x408" alt="@vehicleContent.Name">
}
@*<img class="comingSoon" src="http://placehold.it/650x408" alt="@content.Name">*@
<strong>
<span class="name">@vehicleContent.Name</span>
</strong>
<span class="desc">@vehicleContent.GetPropertyValue("shortContent")</span>
<span class="prx">from, <strong>£@vehicleContent.vehiclePrice</strong> per day</span>
<span class="label label-primary moreinfo">More Info</span>
</a>
</div>
}
</div>
Really struggling in getting the image to render, any ideas why i keep getting ID of the image that is under the media section of umbraco and not the URL?
'Umbraco.Web.Models.PublishedContentBase' does not contain a definition for 'GetPropertyValue'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Umbraco.Web.Models.PublishedContentBase' does not contain a definition for 'GetPropertyValue'
Source Error:
Line 24: @if (vehicleContent.HasValue("vehicleThumbnail"))
Line 25: {
Line 26: var mediaItem = Umbraco.TypedMedia(vehicleContent.GetPropertyValue("vehicleThumbnail"));
Line 27: <img class="featuredVehicleImg img-responsive" src="@mediaItem.GetPropertyValue("umbracoFile")" alt="@mediaItem.Name"/>
Line 28: }
Tried the examples, it is hitting the else statement so it's not picking up the value "vehicleThumbnail"
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using Umbraco.Web
@*
Macro to list nodes from a Multinode tree picker, using the pickers default settings.
Content Values stored as xml.
To get it working with any site's data structure, simply set the selection equal to the property which has the
multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property).
*@
@* Lists each selected value from the picker as a link *@
<div class="featuredVehicles">
@foreach (var id in CurrentPage.featuredVehicles.Split(','))
{
@*For each link, get the node, and display its name and url*@
var vehicleContent = Umbraco.Content(id);
<div class="col-xs-6 col-md-4 col-xs-height">
<a href="@vehicleContent.Url">
@{
if (CurrentPage.HasValue("vehicleThumbnail")){
var dynamicMediaItem = Umbraco.Media(CurrentPage.vehicleThumbnail);
<img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/>
}
else
{
<img class="comingSoon" src="http://placehold.it/650x408" alt="@vehicleContent.Name">
}
}
<strong>
<span class="name">@vehicleContent.Name</span>
</strong>
<span class="desc">@vehicleContent.GetPropertyValue("shortContent")</span>
<span class="prx">from, <strong>£@vehicleContent.vehiclePrice</strong> per day</span>
<span class="label label-primary moreinfo">More Info</span>
</a>
</div>
}
</div>
@* Macro to list nodes from a Multinode tree picker, using the pickers default settings. Content Values stored as xml.
To get it working with any site's data structure, simply set the selection equal to the property which has the multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property). *@
@* Lists each selected value from the picker as a link *@
<div class="featuredVehicles"> @foreach (var id in CurrentPage.featuredVehicles.Split(',')) {
@*For each link, get the node, and display its name and url*@ var vehicleContent = Umbraco.Content(id);
You asked earlier which custom razor script can i use in the dropdown list in the backend of Umbraco. Don´t know if there where any that you can use so I made something to you that I think could be a good starting point.
Since Ido not know yourcontent structure100%, I have mademy suggestionsfor yourRazorbit moregeneric. But feel free to change it so it match your setup. In the first example we are seaching the whole content struture for pages with the "Article" as the document type. Then you need to insert the partial view macro on the page or template where you want it to display.
@{ var selection = CurrentPage.AncestorOrSelf(1).Descendants("Article");
In the next example in assume that the articles are childs to an overview page, it could be a blog document type. So what we do in the next example we find the first page of with document type of Blog, and then loop though it´s children.
@{ @*Get the root of the website *@ var root =CurrentPage.AncestorOrSelf(1).Descendants("Blog").FirstOrDefault(); }
And if you are allow other document types under the Blog that not is of the "Articles", and you only want to pull out the pages with the "Article" documentype, then you can extend the Children() with this:
root.Children("Article").Where("Visible")
Or
root.Articles.Where("Visible")
The last option you, is to use the query bulider, if you are using Umbraco 7.2.2 or later Umbraco 7.2.3 just become available today :) you have the option to use the query builder, that can helps you with make some basic queries to get the right content. It could be get all the articles from the blog overview page, like you want, and order the results by create date in the order of descendants.
When you are in a parial view or partial view marco you can find the query button in the ribbon, I have made a screenshot below.
I used the script list child pages from changeable source, created parameters on the macro and rendered the macro in my view. Worked flawlessly, good examples shown by yourself there as well, Nice one Dennis.
Here is how i did it;
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
=== Macro Parameters To Create ===
Alias:nodeId Name:Node ID Type:Content Picker
*@
@if (Model.MacroParameters["articleLister"] != null)
{
@* Get the start node as a dynamic node *@
var startNode = Umbraco.Content(Model.MacroParameters["articleLister"]);
if (startNode.Children.Where("Visible").Any())
{
<div class="blogSideBar">
<h2 class="archiveHeading">Blog Archive</h2>
<ul class="archiveList noBullets">
@foreach (var page in startNode.Children.Where("Visible").OrderBy("CreateDate desc").Take(30))
{
<li class="fa fa-arrow-circle-right">
<a class="articleLink" href="@page.Url">@page.Name</a>
<span class="dateCreated col-lg-12">@page.CreateDate.ToString("dd/MM/yyyy")</span>
</li>
}
</ul>
</div>
}
}
I'll save the snippet of codes you've provided above for future references :-)
In case anybody else comes across this, I had this issue and I figured out the problem was due to dynamic syntax. That is, I had some code like this:
var thumbnail = helper.TypedMedia(item.thumbnail.InnerText);
var url = thumbnail.GetPropertyValue("umbracoFile");
The item variable in my case was of type dynamic. Extension methods do not work on dynamic variables, so the compiler was looking for a function called GetPropertyValue on the thumbnail instance itself (rather than the extension method). I was able to fix this by adding a cast (so the thumbnail variable was no longer dynamic):
var thumbnail = helper.TypedMedia(item.thumbnail.InnerText as string);
var url = thumbnail.GetPropertyValue("umbracoFile");
PublishedContentBase does not contain a definition for 'GetPropertyValue'
Hi,
I've created a multinode tree picker datatype and trying to list the the thumbnail of a vehicle as part of the foreach loop, however i keep getting the error message;
Below is the razor code;
Tried .umbracoFile and .Url but neither seems to work.
Hello,
Did you add the Umbraco.Web namespace at the top of your Razor file?
GetPropertyValue is an extension method which is in that namespace.
Jeroen
The problem is that your content is a dynamic object. This doesn't have GetPropertyValue method
To solve this you should use :
Probably you will get some errors on other lines in your code where you get the properties shortContent, vehiclePrice
You should convert them to :
Dave
Yes, I've added that now get this error message
This is confusing me now. If i cannot use 'GetPropertyValue' then what can i use instead? TypedMedia?
Thank you Javed
Hi Javed,
WHat did not work. Jeroen's or mine solution ?
Dave
Dave,
Where you have put id do i pass the nodeId in to there and then convert my proprties like this content.GetPropertyValue("yourpropertyalias") ???
Thanks Javed
I'm sorry my solution is probably wrong. I was confused with GetPropertyValue<string>("alias") instead of just GetPropertyValue("alias").
Jeroen
Right guys,
Here is the updated code, now i'm having trouble getting the image out, it's hitting the if statement, missing that and executing the else statement;
Screenshot: http://prntscr.com/6hyw6u
I keep getting the imageID rendering in the source, however i want to render the URL of the image. tried
HTML
Neither seems to work.
Really struggling in getting the image to render, any ideas why i keep getting ID of the image that is under the media section of umbraco and not the URL?
Hello,
Did you try this?
Jeroen
Hi Jeroen,
I've tried but keeping get this error;
Any other alternatives?
Try some of the examples from here: https://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker
Jeroen
This is the setup in the backend of Umbraco
http://imgur.com/ZgPIgMt
http://imgur.com/XsL8zKL
http://imgur.com/RiIgeQl
http://imgur.com/9EsltHP
Does that look all correct to you Jeroen?
Tried the examples, it is hitting the else statement so it's not picking up the value "vehicleThumbnail"
Hi Mohammad,
What if you do something like this, would this work for you to get the image?.
Hope this helps,
/Dennis
Dennis - YOU ARE A LEGEND!
That worked flawlessly. Wow - that was a hurdle. Definitely keeping hold of this snippet of code and cherishing it for as long as i use Umbraco.
Love Umbraco Community, Love Umbraco!
Thanks to everyone that have taken the time to help the annoying me!
Javed.
Hi Javed,
You are welcome happy that I could help you.
Happy Umbraco coding, and thanks for the nice words :-),
/Dennis
You're welcome :-)
Hi Javed,
You asked earlier which custom razor script can i use in the dropdown list in the backend of Umbraco. Don´t know if there where any that you can use so I made something to you that I think could be a good starting point.
Since I do not know your content structure 100%, I have made my suggestions for your Razor bit more generic. But feel free to change it so it match your setup. In the first example we are seaching the whole content struture for pages with the "Article" as the document type. Then you need to insert the partial view macro on the page or template where you want it to display.
@{
var selection = CurrentPage.AncestorOrSelf(1).Descendants("Article");
}
<ul>
@foreach(var item in selection.Where("Visible")){
<li>
<a href="@item.Url">@item.Name</a>
</li>
}
</ul>
In the next example in assume that the articles are childs to an overview page, it could be a blog document type. So what we do in the next example we find the first page of with document type of Blog, and then loop though it´s children.
And if you are allow other document types under the Blog that not is of the "Articles", and you only want to pull out the pages with the "Article" documentype, then you can extend the Children() with this:
Or
The last option you, is to use the query bulider, if you are using Umbraco 7.2.2 or later Umbraco 7.2.3 just become available today :) you have the option to use the query builder, that can helps you with make some basic queries to get the right content. It could be get all the articles from the blog overview page, like you want, and order the results by create date in the order of descendants.
When you are in a parial view or partial view marco you can find the query button in the ribbon, I have made a screenshot below.
Hope this helps, and make sense.
/Dennis
Hi Dennis,
I used the script list child pages from changeable source, created parameters on the macro and rendered the macro in my view. Worked flawlessly, good examples shown by yourself there as well, Nice one Dennis.
Here is how i did it;
I'll save the snippet of codes you've provided above for future references :-)
Many Thanks Javed
In case anybody else comes across this, I had this issue and I figured out the problem was due to dynamic syntax. That is, I had some code like this:
The
item
variable in my case was of typedynamic
. Extension methods do not work on dynamic variables, so the compiler was looking for a function calledGetPropertyValue
on thethumbnail
instance itself (rather than the extension method). I was able to fix this by adding a cast (so thethumbnail
variable was no longer dynamic):And I didn't get an error after that.
is working on a reply...