Copied to clipboard

Flag this post as spam?

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


  • RunnicFusion 62 posts 145 karma points
    Apr 12, 2016 @ 08:30
    RunnicFusion
    0

    Get member properties in Umbraco 7

    I'm currently working on a website that need to load data from a member.

    When I retrieve the member data trough this method I get my custom properties.

    public class DashboardController : SurfaceRenderMvcController
    {
        [DonutOutputCache(CacheProfile = "OneDay")]
        public ActionResult Dashboard()
        {
            var model = ModelLogic.CreateMasterModel() as MasterModel<Dashboard>;
    
            model.Content.Member = Members.GetCurrentMember() as Vendor;
    
            return CurrentTemplate(model);
        }
    }
    

    The problem is that I can load my custom properties like a phone number field but I can't access the default properties like Email and Name this way. That data is available trough the Members.GetCurrentMemberProfileModel (). But than my phone number field is not available.

    What is the corect way of doing this?

    The code i'm using is from: https://live4coding.wordpress.com/2014/08/01/using-role-based-authentication-in-umbraco/

    I'm using the ZBU Models Builder (my vendor is a generated model based on my member type - vendor)

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 12, 2016 @ 08:39
    Dave Woestenborghs
    100

    Hi Runnice Fusion,

    You can create a partial class with the name "Vendor" in the same folder where you generate your content models.

    On this class you can set this property

    /// <summary>
            /// Gets the email.
            /// </summary>
            public string Email
            {
                get
                {
                    return this.GetPropertyValue<string>("Email");
                }
            }
    

    For some reason Zbu doesn't generate a property for the e-mail.

    Dave

  • RunnicFusion 62 posts 145 karma points
    Apr 13, 2016 @ 07:24
    RunnicFusion
    0

    Hi Dave,

    Thanks for your reply. The solution you've provided worked.

Please Sign in or register to post replies

Write your reply to:

Draft