I faced the same issue and after a lot of search i didn't find any simple way
so i try to find my way
1- after we create the user we put this user in a group this group has permission for the pages and the buttons inside every single page in the system
2- users have two permission types:
a- Master user: have full access to the system pages and buttons
b- Normal user: have limited access to pages and buttons inside the page
3- in my HTML view first thing I do is find all buttons in the view
using var buttons = document.getElementsByTagName('button');
in this way, i collect all buttons
then in $(document).ready() function i do my job using ajax like this
$.ajax({
url: '@Url.Action(MyFunction, ControllerName)',
method: 'GET',
success: function (data) {
for (var i = 0; i < buttons.length; i++) {
var button = buttons[i];
var name = button.getAttribute('name');
if (name == "Add" && data.AddPer == 0) {
$("#" + button.getAttribute('id')).addClass("disabled");
}
else if (name == "Print" && data.PrintPer == 0) {
$("#" + button.getAttribute('id')).addClass("disabled");
} else if (name == "Edit" && data.EditPer == 0) {
$("#" + button.getAttribute('id')).addClass("disabled");
}
}
},
error: function () {
// Handle errors if needed
}
});
what I am doing is after I collect all buttons I get my permission from my database and give the button's name then in my for loop i try to know if this button is Add button and the user have permission for this button or not
if not I add class disabled for this button else I don't do any thing for the button
Note: give your buttons a name like I do
I want to say I can customize my solution and make it in a separate javascript file and call it inside your HTML View and pass the parameter you need.