Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mohammad Javed 64 posts 373 karma points
    Mar 17, 2015 @ 13:27
    Mohammad Javed
    0

    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.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 17, 2015 @ 18:16
    Jeroen Breuer
    1

    Hello,

    Did you add the Umbraco.Web namespace at the top of your Razor file?

    @using Umbraco.Web

    GetPropertyValue is an extension method which is in that namespace.

    Jeroen

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Mar 17, 2015 @ 18:20
    Dave Woestenborghs
    1

    The problem is that your content is a dynamic object. This doesn't have GetPropertyValue method

    To solve this you should use :

    var content = Umbraco.TypedContent(id);

    Probably you will get some errors on other lines in your code where you get the properties shortContent, vehiclePrice

    You should convert them to :

    content.GetPropertyValue("yourpropertyalias")

    Dave

  • Mohammad Javed 64 posts 373 karma points
    Mar 17, 2015 @ 18:20
    Mohammad Javed
    0

    Yes, I've added that now get this 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 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?

    Thank you Javed

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Mar 17, 2015 @ 18:27
    Dave Woestenborghs
    0

    Hi Javed,

    WHat did not work. Jeroen's or mine solution ?

    Dave

  • Mohammad Javed 64 posts 373 karma points
    Mar 17, 2015 @ 18:28
    Mohammad Javed
    0

    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

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 17, 2015 @ 18:29
    Jeroen Breuer
    0

    I'm sorry my solution is probably wrong. I was confused with GetPropertyValue<string>("alias") instead of just GetPropertyValue("alias").

    Jeroen

  • Mohammad Javed 64 posts 373 karma points
    Mar 17, 2015 @ 18:38
    Mohammad Javed
    0

    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;

    @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>
    

    Screenshot: http://prntscr.com/6hyw6u

  • Mohammad Javed 64 posts 373 karma points
    Mar 18, 2015 @ 11:12
    Mohammad Javed
    0

    I keep getting the imageID rendering in the source, however i want to render the URL of the image. tried

    @vehicleContent.GetPropertyValue("vehicleThumbnail").Url`
    
    @vehicleContent.GetPropertyValue("vehicleThumbnail").umbracoFile
    
    @vehicleContent.GetPropertyValue("umbracoFile")
    

    HTML

    <img class="featuredVehicleImg img-responsive" src="1092" alt="Pharmaceutical Vehicle One">
    

    Neither seems to work.

  • Mohammad Javed 64 posts 373 karma points
    Mar 19, 2015 @ 11:53
    Mohammad Javed
    0

    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?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 19, 2015 @ 12:03
    Jeroen Breuer
    0

    Hello,

    Did you try this?

    var mediaItem = Umbraco.TypedMedia(vehicleContent.GetPropertyValue("vehicleThumbnail"));                    
    <img class="featuredVehicleImg img-responsive" src="@mediaItem .GetPropertyValue("umbracoFile")" alt="@mediaItem .Name"/>    

    Jeroen

  • Mohammad Javed 64 posts 373 karma points
    Mar 19, 2015 @ 12:08
    Mohammad Javed
    0

    Hi Jeroen,

    I've tried but keeping get this error;

     '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:                 }
    

    Any other alternatives?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 19, 2015 @ 12:10
  • Mohammad Javed 64 posts 373 karma points
    Mar 19, 2015 @ 12:39
    Mohammad Javed
    0

    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"

    @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>&pound;@vehicleContent.vehiclePrice</strong> per day</span>
    
                    <span class="label label-primary moreinfo">More Info</span>
    
                </a>
            </div>
        }
    </div>
    
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 19, 2015 @ 13:11
    Dennis Aaen
    102

    Hi Mohammad,

    What if you do something like this, would this work for you to get the image?.

    @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 dynamicMediaItem = Umbraco.Media(vehicleContent.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>&pound;@vehicleContent.vehiclePrice</strong> per day</span>

                    <span class="label label-primary moreinfo">More Info</span>

                </a>
            </div>
        }
    </div>

    Hope this helps,

    /Dennis

  • Mohammad Javed 64 posts 373 karma points
    Mar 19, 2015 @ 13:20
    Mohammad Javed
    1

    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.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 19, 2015 @ 13:24
    Dennis Aaen
    1

    Hi Javed,

    You are welcome happy that I could help you.

    Happy Umbraco coding, and thanks for the nice words :-),

    /Dennis

  • Mohammad Javed 64 posts 373 karma points
    Mar 19, 2015 @ 14:10
    Mohammad Javed
    0

    You're welcome :-)

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 19, 2015 @ 19:06
    Dennis Aaen
    1

    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.

    @{
       
    @*Get the root of the website *@
       
    var root =CurrentPage.AncestorOrSelf(1).Descendants("Blog").FirstOrDefault();
    }

    <ul>
       
    @foreach(var page in root.Children.Where("Visible"))
       
    {
           
    <li class="@(page.IsAncestorOrSelf(CurrentPage) ? "current" : null)">
               
    <a href="@page.Url">@page.Name</a>
            </
    li>
       
    }
    </ul>

    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.


    Hope this helps, and make sense.

    /Dennis

  • Mohammad Javed 64 posts 373 karma points
    Mar 20, 2015 @ 10:43
    Mohammad Javed
    0

    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;

    @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 :-)

    Many Thanks Javed

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    May 10, 2016 @ 22:43
    Nicholas Westby
    0

    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");
    

    And I didn't get an error after that.

Please Sign in or register to post replies

Write your reply to:

Draft