Copied to clipboard

Flag this post as spam?

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


  • Paul de Quant 403 posts 1520 karma points
    Aug 23, 2019 @ 11:01
    Paul de Quant
    0

    Custom property from Umbraco.Content in v8

    Hello,

    Hopefully, this is an easy one for somebody here.

    I'm using Umbraco.Content() and I need to get a propertyvalue.

    In version 7 I could just write:-

    page1.GetPropertyValue

    but in Umbraco 8 I don't seem to have this option anymore. I've used Model.Value() in other parts of v8 but it's not available for the page I'm working on Umbraco.Web.Mvc.UmbracoViewPage

    Any ideas how I can pull a custom property from Umbraco.Content in v8?

    Thanks

  • Nik 1612 posts 7258 karma points MVP 7x c-trib
    Aug 23, 2019 @ 11:10
    Nik
    100

    Hi Paul,

    It should be available.

    Umbraco.Content() returns either a single IPublishedContent or an IEnumerable<IPublishedContent> depending on what you pass into it.

    The method .Value, I believe, is an extension method for the IPublishedContent interface so should be readily available if you have the standard web.config in your views folder as this should have all the name spaces defined. If you have the single object returned it should be there, else if you have had an IEnumerable returned you'll need to loop around it to get each individual element and call .Value on that.

    It is possible that you are missing the namespace however, in which case you need to ensure that you are referencing the Umbraco.Web namespace for it to be available.

    Nik

  • Paul de Quant 403 posts 1520 karma points
    Aug 23, 2019 @ 11:15
    Paul de Quant
    1

    Hi Nik,

    Thanks for the reponse, it was the missing namespace that I needed Umbraco.Web. Can't believe I overlooked this one.

    Cheers Paul

  • Lander Debeuf 23 posts 125 karma points
    Oct 15, 2019 @ 08:48
    Lander Debeuf
    0
    page1.GetProperty("name").Value<string>();
    
Please Sign in or register to post replies

Write your reply to:

Draft