How can I split a controller in ASP.NET MVC while keeping the controller name?

I'm working on a controller that is part of a very flat page hierarchy, and it looks like there can be more than a dozen action methods in one section of a site, not counting their corresponding actions with articles. Is there a good way to split this controller while keeping the partition name? I do not want the controller class to get out of hand.

+4
source share
3 answers

If your controller class gets out of control for a dozen actions, you may need to rethink how much logic should be there and how much can be reorganized into services.

In addition, if your controller reaches more than a dozen actions, you might be wondering if it can be divided into separate controllers. Remember that you can change the routing rules and the factory controller so that the URL remains the same, but the controller crashes.

If it’s convenient for you that you did what you can, and still want to split it into separate files, use a partial class.

+5
source

If I understand correctly, you just want to split the class into several files so that each file is easier to understand.

This means that you want to use Partial classes . They allow you to split the definition of one class into several files.

+3
source

Take a look at this . Worked for me very well.

0
source

Source: https://habr.com/ru/post/1301707/


All Articles