tags:

views:

24

answers:

1

I have a situation where a controller action should result in the information about a given object being displayed differently depending on the user's permission on the object.

Currently the controller action code returns one of two views accordingly: Info.ascx or Info_ViewOnly.ascx.

As the differences between these two views are very minor (and I have just had to update each with a format change) I am considering having one view (Info.ascx) and passing the user's permission to the view using the View's Model.

Which approach would you consider preferable? Alternative suggestions also welcome :-)

+1  A: 

The presence of "If Else" logic in your views is a good indication that you may need to split the view into multiple respective views. Your controller is probably the best place to assess user permissions and route the request to the most appropriate view - therefore that "If Else" logic should probably occur in the controller rather than the view.

Ben Elder
Seems that both Views would be based on almost the same model. If you were to create two different views, you're running into code reuse problems.
Yuriy Faktorovich
Good use of UserControls can help reduce redundant code between the two views (e.g. a core menu of options available to both permissions), but separating the views can make maintenance in the future easier when new requirements further differentiate the presentation components for each permission type. Ultimately, i think this may be a case where you can spend too much time splitting hairs about whether to split the views - if a consolidated view is maintainable then there is no steadfast rule saying you shouldn't keep it consolidated.
Ben Elder
Thanks for the suggestions - this was really what I was weighing up and I just wondered if there was any kind of preferred convention.
TonE