I am currently working on an MVC 3 Web app project where I need to display a lot of information on the front page. I am relatively new at web page layout and design so I have hit a wall in terms of how to structure the code behind for this page.
My first thoughts were to split the page up into as many partials as possible so the View Models are smaller and easier to manage. Although I am not sure if this is the correct way of going about it. Or should I try to fit all the needs of the page into one view model that will display all the information I need?
My question: Should I split my pages up into a lot of small partials or just make it one big page?
Well, I think you should split big views into partials, just like it’s preferred to split big methods into smaller ones. The big great views tend to become maintainable only by original creator.
Basic rules, analogous to splitting code into methods, should be applied:
- don’t split too much — if the view code does not exceed one-two screens it’s perfectly OK (with the exception of extracting reusable parts)
- don’t mix low level details with high level concepts — partials placed at the top level in your view should represent the same level
of generality - rely as little as possible on state maintained somehwere else
Also, use Razor’s Display/EditorTemplates whenever possible – they are very helpful kind-of partial views. Get familiar with their abilities of rendering (and model-binding) for collections.
1