Answer the question
In order to leave comments, you need to log in
How to display views depending on the user's role?
I have a view Manage/Index.cshtml , three roles Admin, SuperUser, User and three tables in the database. I need to display all three tables in this view for the Admin role, two tables for the SuperUser role, and one table for the User. These tables also need to be changed. How to implement this correctly?
Output and editing of tables is carried out through Entity framework 6, a project on MVC5
Answer the question
In order to leave comments, you need to log in
It is better to solve the task at the controller level, and not in the view. Depending on the role, create appropriate queries to the database, and only one model with results should go to the view. How to render the result in the view is another task. And it will be even easier to implement changes in tables. Will you display the ID field in the model? It is enough to implement editing of individual records, regardless of roles.
Suppose there is such a model
public class Category
{
public string Name{ get; set; }
public Users User { get; set; }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question