In ASP.NET MVC (3.0/Razor), do you prefer multiple views, or conditionals within views? Why?
Posted
by
Chad
on Stack Overflow
See other posts from Stack Overflow
or by Chad
Published on 2011-01-07T05:24:36Z
Indexed on
2011/01/07
5:54 UTC
Read the original article
Hit count: 262
For my new web app, I'm debating on using multiple views, or conditionals within views.
An example scenario would be showing different info to users who are authenticated vs non-authenticated. This could be handled a couple ways.
- In the controller, check IsAuthenticated and return a view based on that
- In the view, check IsAuthenticated and show blocks of info based on that
Pros of multiple views: Smaller, less complicated view - next to no logic in the view
Pros of single views: less view files to maintain
The obvious cons are the opposites of the pros: more files to maintain or more complicated view files.
Which do you prefer? Why? Any pros/cons I haven't outlined here?
Update: Assume each view uses a layout page and partial views to abstract the obviously repetitive code.
© Stack Overflow or respective owner