Copied to clipboard

Flag this post as spam?

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


  • Peter Holmsgaard 69 posts 106 karma points
    Mar 31, 2011 @ 15:28
    Peter Holmsgaard
    0

    Working with members and Razor

    Hey

    I created a thread earlier on how to get the name of the current member logge in - no sweat.

    Now i wan't to use some custom properties from the member, ie. memberPhone. How do i access those? I've used this to get hold of the other userdata:

    @using System.Web.Security

    @ {
       var member = Membership.GetUser();
    }

    You are logged in as:
    @member.UserName
    @member.Email

    I have been looking into the Umbraco wiki (http://our.umbraco.org/wiki/how-tos/membership-providers @ Setting a Profile Property) - I've added the field alias to my webconfig, but still no result. 

    In my other projects, with XSLT, i have a extension from which i can call ie. GetMember('string'), GetMembersAll() ect. Can I reuse it somehow by adding it as a namespace, abit like I do when adding it as an XSLT extension?

     

     

     Anyone that can help?

    /Peter

  • Peter Holmsgaard 69 posts 106 karma points
    Mar 31, 2011 @ 15:28
    Peter Holmsgaard
    0

    Oh and btw, I'm running a umb version 4.7

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Mar 31, 2011 @ 15:30
    Sebastiaan Janssen
    0

    You can just access your XSLT extension in exactly the same way that you would in XSLT itself, just replace the ":" with a ",". For example, one of Umbraco's extensions:

    @umbraco.library.NiceUrl(@Model.Id)
  • Peter Holmsgaard 69 posts 106 karma points
    Mar 31, 2011 @ 15:52
    Peter Holmsgaard
    0

    If I try this:

    @umbraco.library.GetMember(1129)

    I get this error in the frontend:

    MS.Internal.Xml.XPath.XPathSelectionIterator

    /Peter

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Mar 31, 2011 @ 16:00
    Sebastiaan Janssen
    1

    Hehe, that's not an error, it's the type name of the result of that function call. You're getting back an XPathSelectionIterator (which would be very convenient if you were using XSLT).

    But how about just doing something like this [edit: updated code as per comments below]:

    @using umbraco.cms.businesslogic.member
    @{
        var member = new Member(1129);
        var userName = member.Name; //not sure if this is available, could be called something else
        var email = member.Email; //not sure if this is available, could be called something else
        var someProperty = member.getProperty("myCustomProperty").Value.ToString();
    }
  • Peter Holmsgaard 69 posts 106 karma points
    Mar 31, 2011 @ 16:17
    Peter Holmsgaard
    0

    Allrighty.. Well, I would prefer xslt ;)

    Well, if i use the chunk of code you just made, i get this "Error"

    Error occured
    c:\sites\videnbank\macroScripts\634371848915625000_CurrentMember.cshtml(5): error CS0246: The type or namespace name 'Member' could not be found (are you missing a using directive or an assembly reference?)

    Am I missing a namespace?

    /Peter

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Mar 31, 2011 @ 16:26
    Sebastiaan Janssen
    0

    Ah yes sorry, you should add:

    @using umbraco.cms.businesslogic.member
  • Peter Holmsgaard 69 posts 106 karma points
    Mar 31, 2011 @ 16:31
    Peter Holmsgaard
    0

    Ahh sweet..

    Now we're allmost there, I'm guessing i need another, since i get this error:

    ....error CS1061: 'umbraco.cms.businesslogic.member.Member' does not contain a definition for 'GetProperty' and no extension method 'GetProperty' accepting a first argument of type 'umbraco.cms.businesslogic.member.Member' could be found (are you missing a using directive or an assembly reference?)

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Mar 31, 2011 @ 17:24
    Sebastiaan Janssen
    0

    Argh, my fault entirely, it's getProperty with lowercase "g".

  • Peter Holmsgaard 69 posts 106 karma points
    Mar 31, 2011 @ 17:30
    Peter Holmsgaard
    1

    Sweetness, it works..

    Thanks for your time Sebastiaan :)

  • Ezgi 7 posts 27 karma points
    Jan 05, 2013 @ 12:36
    Ezgi
    0

    Hi, 

    I got a problem about this:

    i just put this code in the Address.cshtml file in ucommerce

    @using umbraco.cms.businesslogic.member
     @{var member = new Member(Convert.ToInt32(memberId));
            var userName = member.Name; //not sure if this is available, could be called something else
            var email = member.Email; //not sure if this is available, could be called something else
            var addressline1 = member.getProperty("addressline1").Value.ToString();
     }
    and then i put this value in the address line like this:
    <input type="text" class="span12 required" name="billing-line1" value="@addressline1" placeholder="Street" />
    
    but it gets  loading MacroEngine script error.. what do u think causes the problem? thanks..
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 05, 2013 @ 15:00
    Jan Skovgaard
    0

    Hi Ezgi and welcome to our :)

    What happens if you uncomment the username and email variables? Is it the complete code you have posted above? If so where does the memberId variable get it's value from?

    /Jan

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

    Hi Jan, thanks..

     

    getProperty and var mymember = Member.GetCurrentMember()


    dont works in my cshtml file.
    @using UCommerce.Api
    @using umbraco.cms.businesslogic.member
    @using System.Web  
    @using System.Web.Security
    @using UCommerce.EntitiesV2
    @using UCommerce.Extensions
    @using UCommerce.Runtime
    @using umbraco.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:29
    Jan Skovgaard
    0

    Hi Ezgi

    As I just wrote in another reply in another post - what version of Umbraco are you using? If 4.11 are you then using MVC?

    Looking forward to hearing from you.

    /Jan

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

    Hi Jan,

    It is 4.9. I guess the Member object does not function properly for my site.. thanks in advance

Please Sign in or register to post replies

Write your reply to:

Draft