Search code examples
c#razorumbraco

How can I access user type from Razor html (Umbraco)


I use Umbraco and I need to hidden tags for some user roles. How can I know user role in view?


Solution

  • The User class has a built in function IsInRole(string roleName). In your view, you would put something like this:

    @if (User.IsInRole("myRole")){
    
        @html.editorfor....
    }else{
    
        @html.hiddenfor...
    }