Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to split an MVC view into two?

I discussed best practices in MVC the other day with a colleague and he asked me how to best separate views. He was maintaining an MVC solution which had a common input form with a controller with two actions, a get action, and a post action. Both actions were returning the same view, which was filled with inline logic, and conditionals checking whether it was a post or a get.

What is the best solution for this situation? Should the view be split into two separate views? I guess it depends on how much logic is in there, but when is too much? Is there a way to quantify when you can motivate the refactoring into two views?

like image 523
Rickard Avatar asked Sep 24 '11 23:09

Rickard


1 Answers

I would definitely separate something like that into two separate views and then use partial views for the parts that are in common between them.

Composition, without inheritance and without conditional logic, is nearly always the cleaner, clearer, more maintainable way to go when it comes to planning Views.

like image 148
Ian Mercer Avatar answered Sep 18 '22 16:09

Ian Mercer