Copied to clipboard

Flag this post as spam?

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


  • Michael Knudsen 18 posts 40 karma points
    Oct 08, 2012 @ 13:04
    Michael Knudsen
    0

    Getting member properties

    Hi,I can get the currentMember Id using the following - but how do I get member properties - I tried the getProperty method, but that gives an error.my test code:@using umbraco.cms.businesslogic.member.. var member = Member.GetCurrentMember(); <span>@member.Id</span> - works fine<br/> <span>@member.getProperty("Name").Value</span> - breaks the macro<br/>..i tried with ToString() and without .Value - that works, but nothing gets returned.my guess is that properties are not availeble on the member object - but it must be possible to get them somehow - in RazorA tip to an example on how to access the standard member properties and custom properties would be perfect.regardsMichael

  • Michael Knudsen 18 posts 40 karma points
    Oct 08, 2012 @ 13:32
    Michael Knudsen
    0

    maybe I just found something...

     

    var mymember = Member.GetCurrentMember();
     var test = mymember.HasProperty("logo");

     

    that returned true - and I can get the property with mymember.getProperty("logo").Value

    that was what i wanted... - happy days :-)

    and I can use this as well:
    mymember.Email
    .Id

    and another custom property with the getProperty method

    But what about the Name - and other properties?

     

    /Michael

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 08, 2012 @ 14:05
    Fuji Kusaka
    0

    Hi Michael,

    You could do something like

    var mymember = Member.GetCurrentMember();

    var userName = mymember.getProperty("Name").Value.ToString();
    <p>@userName</p>
  • Michael Knudsen 18 posts 40 karma points
    Oct 08, 2012 @ 21:44
    Michael Knudsen
    0

    strange - that gives an error..

    Error loading MacroEngine script

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 09, 2012 @ 07:18
    Fuji Kusaka
    0

    Can you post the whole code ?

  • Michael Knudsen 18 posts 40 karma points
    Oct 09, 2012 @ 10:46
    Michael Knudsen
    0

    i used
    var mymember =Member.GetCurrentMember();

    var userName = mymember.getProperty("Name").Value.ToString();

     

    But I now use this - and it works:
    @using umbraco.cms.businesslogic.member
    @{

     
     var mymember = Member.GetCurrentMember();
     var userName = mymember.Text;
     <span>@userName</span>
     
    }  

     

    But I think its strange that properties cant be accessed the same way.

    Isnt there some doc. on using Members from Razor (or xsl)

     

    /Mic

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 09, 2012 @ 11:15
    Fuji Kusaka
    0

    Do you have those namespace in your razor file ?

    @using umbraco.cms.businesslogic.member
    @using System.Web 
    @using System.Web.Security

  • Michael Knudsen 18 posts 40 karma points
    Oct 09, 2012 @ 11:33
    Michael Knudsen
    0

    only the first one actually... - is that the trick?

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 09, 2012 @ 11:37
    Fuji Kusaka
    0

    Yes it should get you working...

  • Ezgi 7 posts 27 karma points
    Jan 05, 2013 @ 16:02
    Ezgi
    0

    Hi all, 

    these methods dont work in my address.cshtml file, why do you think so?

    thanks

    getProperty andvar mymember =Member.GetCurrentMember()


    dont works in my cshtml file.
    @usingUCommerce.Api
    @usingumbraco.cms.businesslogic.member
    @usingSystem.Web  
    @usingSystem.Web.Security
    @usingUCommerce.EntitiesV2
    @usingUCommerce.Extensions
    @usingUCommerce.Runtime
    @usingumbraco.MacroEngines
    Member m =Member.GetCurrentMember();
    var city= member.getProperty("city").
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 05, 2013 @ 16:28
    Jan Skovgaard
    0

    Hi Ezgi

    What version of Umbraco are you using? If it's 4.11 and you're using MVC razor you perhaps need to do it in another way. The thing is that currently there is macroscript Razor and MVC razor implementations...so what you can do with one implementation may not work with another implementation...

    So it's important to know :)

    Looking forward to hearing from you.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft