Copied to clipboard

Flag this post as spam?

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


  • AJS 31 posts 212 karma points
    May 06, 2016 @ 19:58
    AJS
    0

    Getting username from user ID

    Hi there,

    I have some code that outputs the user ID; however, I want it to output the username instead.

    @if(CurrentPage.HasValue("author"))
    {
        @CurrentPage.author
    }
    else {
        @CurrentPage.WriterName
    }
    

    "Author" is a property that was created with the user picker.

    What should I do. I've tried:

    @CurrentPage.author.Name
    
    @CurrentPage.author.ToString()
    

    And .ToString() outputs the ID and .Name breaks it.

    Any suggestions would be greatly appreciated. Thanks!

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 07, 2016 @ 08:48
    Dennis Aaen
    100

    Hi Amanda,

    You can use the Umbraco helper called @Umbraco.TypedMember to solve this.

    You can use the code below to get the name of the member.

    @if(CurrentPage.HasValue("author"))
    {
       var member = Umbraco.TypedMember(CurrentPage.author);
       @member.Name
    }
    else {
        @CurrentPage.WriterName
    }
    

    Hope this helps,

    /Dennis

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies