How can I create a view that has different displays according to the role the user is in?

后端 未结 8 1352
南方客
南方客 2020-12-04 11:22

I want to create a view that has different displays according to the role the user is in.

Should I create a different view for different roles or should I check the

相关标签:
8条回答
  • 2020-12-04 12:26

    without researching the exact mechanism asp.net mvc uses for roles i would scream no for putting any of your business logic in the view which is what you are doing if you are checking roles in the view

    0 讨论(0)
  • 2020-12-04 12:28

    I have base model which from all others models extend. In this model i have loaded the user's roles. Its based on httpcontext.user.isinrole() method. All views are strong typed expecting the base model type. So i can always check in all views something like Model.CurrentUser.IsInRoles(Role1 | Role2). Not only in views of course, but in hole application.

    0 讨论(0)
提交回复
热议问题