Hide commands/toolbar based on db-based role management

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

    Posted 12 Jan Link to this post

    Hello, 

    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
    Admin
    Dimo avatar
    8333 posts

    Posted 14 Jan 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;
    }
     
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()   
        .Name("Grid")   
        .Columns(columns => {       
            columns.Bound(p => p.ProductName);
            if (userCanEdit)
            {
                columns.Command(command => command.Destroy()).Width(110);
            }
        })
        .ToolBar(toolbar => {
            if (userCanEdit)
            {
                toolbar.Create();
                toolbar.Save();
            }
        })
        .Editable(editable => editable.Mode(GridEditMode.InCell).Enabled(userCanEdit))
    )


    Regards,
    Dimo
    Telerik
    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
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top