ace
ace

Reputation: 215

ASP.Net MVC - Showing Model data based on Roles

I have a View which needs to show and hide details based on the users role. I have 2 options

  1. using an inline if statement in the View to show and hide details
  2. Create multiple partial views and use to controller to detect the role and then load the appropriate Partial view.

Im a newbie to MVC so can someone please advise what the best way is for approaching this problem.

Upvotes: 1

Views: 663

Answers (2)

Esteban Araya
Esteban Araya

Reputation: 29664

I'd probably do different views for every role. I've found that over time the views for each role diverge in "common" content.

Upvotes: 0

stimms
stimms

Reputation: 44094

If it is something related to how the information displayed on the screen (and it sounds like it is) then it is best to keep that in the view. Personally I would use partial views and only load them when needed, this supports better reuse.

Upvotes: 1

Related Questions