Copied to clipboard

Flag this post as spam?

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


  • Aki 43 posts 214 karma points
    Jan 09, 2016 @ 01:03
    Aki
    0

    Umbraco.Content(XXXX) to get Document Property value

    Hello Sorry for this (easy) question I have been messing around with it for a few hours now and i cant get the property to show..

        @{ 
            var Counter = Umbraco.Content(1408);
            var num = Counter.accumulatedClicks;
        }
    

    This should Write back the property right ?

    what i could do is using CurrentPage.Parent.and then find the proper child but i would like to get this working....

    It seemed to work for a few days so im kinda baffeled...

    i use @num to get the number out

    Now the Number i get is 0 which is wrong so i must be doing somthing wrong...

    Looking through the forums yielded no solution

  • Aki 43 posts 214 karma points
    Jan 09, 2016 @ 01:22
    Aki
    0

    Found the solution

    @using Umbraco.Core
    @using Umbraco.Core.Models
    
    @{
     IContent iProp= ApplicationContext.Current.Services.ContentService.GetById(1408);
    }
    
    @iProp.Properties.First(x => x.Alias == "accumulatedClicks").Value
    
  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jan 09, 2016 @ 21:12
    Jeavon Leopold
    100

    Hi there, there is nothing specifically wrong with this code (the capital C in counter could be lower). Have you tried publishing the node again?

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jan 09, 2016 @ 21:53
    Nicholas Westby
    0

    I'm assuming there is some reason you aren't using published content. If that's the case, here's a slightly shorter version of what you posted already:

    var service = ApplicationContext.Current.Services.ContentService;
    var node = service.GetById(1408);
    var value = node.GetValue<int>("accumulatedClicks");
    // If the above doesn't work, try this (then cast/convert/parse as necessary):
    var valueObject = node.GetValue<object>("accumulatedClicks");
    
  • Aki 43 posts 214 karma points
    Jan 10, 2016 @ 01:33
    Aki
    0

    yes the content was/is unpublished..

Please Sign in or register to post replies

Write your reply to:

Draft