Copied to clipboard

Flag this post as spam?

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


  • Tim 66 posts 89 karma points
    Apr 17, 2015 @ 14:58
    Tim
    0

    Single Item mode, getting values

    Hi,

    Firstly, this looks like a great plugin! Just what I need :)

    But, I'm having problems getting the values when it's in a single item mode. I've followed the documentation. I'm using a partial macros

    @inherits Umbraco.Web.Macros.PartialViewMacroPage 
    @{
        var rightbanner = CurrentPage.GetPropertyValue<IPublishedContent>("rightBanner");
        var h4 = rightbanner.GetPropertyValue("h4");
      }

    rightbanner retrieves a value as a Our.Umbraco.NestedContent.Models.DetachedPublishedContent

    but the GetPropertyValue function doesn't get my h4 content.

    Here's a screenshot when debugging. I can see the value, I just don't know how to drill down to it.

    Any help would be appreciated.

    Many Thanks

    Tim

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 17, 2015 @ 16:08
    Lee Kelleher
    0

    Hi Tim,

    When you step on to the next line, does the h4 variable have any value?

    As looking at the debugging data, it should return a value.

    If it doesn't return any value, then you could try an alternative approach:

    var h4 = rightbanner.GetProperty("h4").Value;
    

    Cheers,
    - Lee

  • Tim 66 posts 89 karma points
    Apr 17, 2015 @ 16:16
    Tim
    0

    Hi Lee

    It doesn't return a value. I get the following error.

    Additional information: 'Umbraco.Web.Models.PublishedContentBase' does not contain a definition for 'GetPropertyValue'

    But I've found the solution:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        IPublishedContent rightbanner = CurrentPage.GetPropertyValue<IPublishedContent>("rightBanner");
        var h4 = rightbanner.GetPropertyValue("h4");    
    }

    I changed the var to IPublishedContent and it worked. Not sure if it's because I'm using a Partial Macro instead of a Partial View.

    Thanks

    Tim

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 17, 2015 @ 17:00
    Lee Kelleher
    0

    Hi Tim,

    Glad that you've got it working!

    The error for "'X' does not contain a definition for 'GetPropertyValue'" usually means that the View/Partial is missing a namespace reference. Try adding this to the top of your partial:

    @using Umbraco.Web;
    

    Cheers,
    - Lee

  • Tim 66 posts 89 karma points
    Apr 17, 2015 @ 17:05
    Tim
    0

    Hi Lee,

    Just tried putting in the namespace, it didn't work.

    Seems like it really wants the variable to be defined as a IPublishedContent instead of a var.

    Anyhow it's working and it's perfect for what I needed it for :)

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Apr 17, 2015 @ 17:06
    Lee Kelleher
    0

    OK, no worries - glad it's working now! :-)

Please Sign in or register to post replies

Write your reply to:

Draft