views:

130

answers:

2

Hi, 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.

+1  A: 

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.

stimms
hi, thanks for you response. Partial views sounds like the way to go. Is there a way to dynamically load partial views based from controllers?
ace
Yeah you can either link them in at the asp level http://blogs.intesoft.net/post/2009/02/renderaction-versus-renderpartial-aspnet-mvc.aspx or pull them in using javascript http://www.codeproject.com/KB/aspnet/JQueryPartial.aspx
stimms
A: 

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

Esteban Araya