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

    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

    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 3045 posts 13386 karma points MVP 9x admin c-trib
    Jan 09, 2016 @ 21:12
    Jeavon Leopold

    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 2045 posts 7032 karma points c-trib
    Jan 09, 2016 @ 21:53
    Nicholas Westby

    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

    yes the content was/is unpublished..

Please Sign in or register to post replies

Write your reply to: