How can I hide certain elements in a security-based Razor view without logic in the view?

I searched everything for elegant solutions to this not so long-standing issue. How to block form elements in ASP.Net MVC View without adding if ... then it is logical everywhere?
Ideally, BaseController, whether OnAuthorization, or OnResultExecultion, will check the rendering form elements and hide / not display them based on the role and scope.
Another approach that I examined is to write some kind of custom attributes to stay up to date on how we block ActionResults using [Authorize]. Is it possible even without passing the list of hidden objects to the view and putting all this?

Other background information: we will have a database that tells us at runtime (based on the user's role / area) which elements will be hidden. We are using MVC3 with Razor Viewengine. We use BaseController, where any of the Controller methods can be overridden.

Any help on this would be greatly appreciated!

+7
source share
1 answer

You can use several different methods:

  • Send the user to another view (view only) based on an action filter or condition in the controller.
  • In the field database, you can create logic in the editor templates to read user data annotations based on role / permission.
  • You can create HTML helpers to process the logic and display the corresponding partial view, css class or text.

More details:

+2
source

All Articles