开发者

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, whic开发者_StackOverflow中文版h 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜