How to keep views free of authorization logic in mvc?

Posted by David Lay on Stack Overflow See other posts from Stack Overflow or by David Lay
Published on 2010-04-27T19:43:32Z Indexed on 2010/04/27 19:53 UTC
Read the original article Hit count: 341

I have a view to display a list of items. The user can edit, delete or create new items, but according to their authorizations they may or may not be allowed to do some of this actions.

I have the requirement to display only the actions which the current user is allowed to do, but I don't want to clutter the views with authorization if-else's

Despise of being a very common requirement, I can't find a real satisfactory way of doing it.

My best approach so far is to provide an overload to the Html.ActionLink extension method that takes the permission to ask for, but there are going to be more complex scenarios, like hiding entire blocks of html or switching a textbox for a label+hidden.

Is there a better way to do this?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about validation