Copied to clipboard

Flag this post as spam?

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


  • Li JC 13 posts 93 karma points
    Dec 03, 2019 @ 14:24
    Li JC
    0
    Hello everyone,
    
    Iam trying to get some data from the documention type. 
    
    I have found this solution :
    
    umbracoHelper.Content(2921).GetPropertyValue<string>("aDGroupName");
    
    But is it best pratice? IT is fine to write "aDGroupName" because it is a alias that i haved created. But what about the "umbracoHelper.Content(2921)", because i am hardcoding the id. But what can i do alternativ?
    
    thx
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Dec 03, 2019 @ 15:34
    Alex Skrypnyk
    0

    Hi Li JC

    What Umbraco version are you using?

    It's better to use Models Builder, check out docs - https://our.umbraco.com/documentation/reference/templating/modelsbuilder/

    With Models Builder you will have IntelliSense so you don't need to hardcode a property alias.

    Another question to you, where do you use this code? If it's in view or Umbraco controller you don't need to instantiate UmbracoHelper class, the instance is accessible just by Umbraco.

    Thanks,

    Alex

  • Li JC 13 posts 93 karma points
    Dec 03, 2019 @ 15:50
    Li JC
    0

    Iam using it at controller

Please Sign in or register to post replies

Write your reply to:

Draft