D
D
DSergeev2014-10-12 12:22:33
ASP.NET
DSergeev, 2014-10-12 12:22:33

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

3 answer(s)
O
Oleg Soldatov, 2014-10-22
@Soldata

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.

D
DSergeev, 2014-10-23
@DSergeev

Suppose there is such a model

public class Category
    {
        public string Name{ get; set; }
        public Users User { get; set; } 
    }

When a user with the admin role creates this category, he assigns the user to it. It is necessary that the User role has the right to edit this category, but only its name, so that it cannot change the assigned user. How to be in this case?

A
asdz, 2014-11-13
@asdz

Maybe just in the view to check the membership of the role and, accordingly, display the desired piece of the page?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question