Copied to clipboard

Flag this post as spam?

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


  • Mark Bro 15 posts 86 karma points
    May 29, 2013 @ 02:37
    Mark Bro
    0

    Get custom member properties with razor

    Hi,

    Am trying to retrieve a custom property (customproperty1) from a member however I am having trouble. Any thoughts. Example below (name works fine just not the custom one)

    @using umbraco.cms.businesslogic.member
    @using System.Web 
    @using System.Web.Security@{   
     
    var currentUser = Member.GetCurrentMember();      

     if (currentUser!=null){              

     var _userName = currentUser.Text;
     var _customproperty1 = currentUser.getProperty("Customproperty1");
     
    <p>@_userName </p>
    <p>@_customproperty1 </p> 

    }   
    }

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 29, 2013 @ 18:20
    Jeavon Leopold
    1

    Hi Mark,

    I think you are just missing a .Value

    e.g.

    var _customproperty1 = currentUser.getProperty("Customproperty1").Value 

    I generally perfer to use uQuery when working with members in Razor, there is an example in the docs here

    Thanks,

    Jeavon

     

  • Mark Bro 15 posts 86 karma points
    May 29, 2013 @ 22:11
    Mark Bro
    0

    Thanks for the help Jeavon, have manged to retrieve the custom values using uQuery as you suggested. One question, is there an equivalent Member.GetCurrentMember in uQuery's  uQuery.Get........ ? if not how do you get the current member logged on using uquery?

    Cheers,

    Mark

     

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 29, 2013 @ 22:54
    Jeavon Leopold
    0

    Hi Mark,

    You just do the same as you had before using Member.GetCurrentMember() as the uQuery GetProperty is a extension method on the standard member object so should be available?

    Let me know if that works or not?

    Cheers,

    Jeavon

  • Mark Bro 15 posts 86 karma points
    May 29, 2013 @ 23:28
    Mark Bro
    100

    Hi Jeavon,

    Right that makes sense. I did actually leave the GetCurrentMember in my code, just wanted to make sure that was correct. Thanks again for all your help.

    Just for anyone interested, here's the final code as an example:

    @using umbraco.cms.businesslogic.member

    @{
           var member = Member.GetCurrentMember();      

           if (member != null)
             {
                 //member properties
                 <text>Name: </text>@member.Text<br/>
                 <text>Username: </text>@member.LoginName<br/>
                 <text>Email: </text>@member.Email<br/>
               //custom properties
                 <text>Custom Property Text: </text>@(member.GetProperty<string>("customproperty1")) <br/>
             }
       }

     

     

     

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 30, 2013 @ 10:20
    Jeavon Leopold
    0

    Hi Mark, that's great!

    There are a few other helpful methods for members available from uQuery such as HasProperty, full details here

    Thanks,

    Jeavon

     

  • keilo 568 posts 1023 karma points
    Oct 27, 2014 @ 07:04
    keilo
    0

    Hi Jeavon

    Is there any change, alternative new way of doing the below with update v7 member api? I cant seem to locate a clear reference where it indicates the equivalent of the below code in new alternate api v7. Would you know?

    @using umbraco.cms.businesslogic.member

    @{
           var member = Member.GetCurrentMember();    <p>member.GetProperty<string>("customproperty1"))   </p>

    }

Please Sign in or register to post replies

Write your reply to:

Draft