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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With