When to split an MVC view into two?
Asked Answered
L

1

6

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?

Leonie answered 24/9, 2011 at 23:11 Comment(1)
I would wonder more about why the GET versus POST conditionals were required. It seems to be typical to use the same view for GET and POST for a form and then redirect to next step/confirmation on POST success (PRG). It is not common to have GET versus POST conditionals in the views though.Heading
S
3

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.

Spiritism answered 25/9, 2011 at 0:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.