I'm working on a controller that is a part of a very flat hierarchy of pages, and it looks like one section of the site could have over a dozen action methods, not including their corresponding post actions. Is there a good way to break this controller up while still preserving the section 开发者_运维技巧name? I don't want that controller class getting out of control.
If your controller class is getting out of control on a dozen actions, you might want to rethink how much logic should be in there and how much can be refactored out into services.
Also, if your controller is getting up to much more than a dozen actions, you might want to consider whether it can be broken down into separate controllers. Remember, you can change the routing rules and controller factory such that the URL remains the same but the controller is broken up.
If you're comfortable that you've done what you can and still want to break it into separate files - use a partial class.
If I understand correctly, you just want to split a class across multiple files so each file is easier to understand.
That would mean you want to use Partial Classes. They allow you to split the definition of a single class across multiple files.
Take a look at this. Worked for me just fine.
精彩评论