Getting Current User's Roles from View

Topics: General, Writing modules
Apr 22 at 12:04 AM
Edited Apr 22 at 12:17 AM
I tried this code but it always returns 0 roles:
var roles = ((ContentItem)WorkContext.CurrentUser.ContentItem).As<UserRolesPart>().Roles;
I got this code from here:

Apr 29 at 4:51 PM
Well, the problem was not with the code it was with the admin account. Being the superuser, it did not have any roles. I was thinking it had administrator role but it does not. I tried with another account and it worked fine.
Marked as answer by matthewjamesr on 4/29/2016 at 9:51 AM