Hide commands/toolbar based on db-based role management

2 posts, 0 answers
  1. Oliver
    Oliver avatar
    8 posts
    Member since:
    Jun 2015

    Posted 12 Jan 2016 Link to this post


    the AuthorizeAttribute does for well initial authorization and authentication and for actions that return views, but it doesn't work for grid commands such as save. Well it actually prevent the saving process, but the routing to the error-action doesn't work properly, because the save-command doesn't expect a view to be returned.


    Rather than redirecting I'd like to hide commands/toolbar-items based on the role a user has in our database, but so far I only found an option like this based on AD-roles. Is there any way for me to do this?

  2. Dimo
    Dimo avatar
    8452 posts

    Posted 14 Jan 2016 Link to this post

    Hello Oliver,

    Unfortunately, there is no built-in way to manage the toolbar and command buttons' visibility, depending on the user role. A possible way to achieve the desired behavior is to make the Grid configuration dependent on a boolean flag, for example:

        var userCanEdit = false;
        .Columns(columns => {       
            columns.Bound(p => p.ProductName);
            if (userCanEdit)
                columns.Command(command => command.Destroy()).Width(110);
        .ToolBar(toolbar => {
            if (userCanEdit)
        .Editable(editable => editable.Mode(GridEditMode.InCell).Enabled(userCanEdit))

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top