0

I have MVC app and when I create I start with one controller for my domain model Person. I have actions including AddPerson, DeletePerson, EditPerson, etc. Then I start adding more like AddPersonBoss and RemovePersonBoss. Pretty soon I have 20 actions in one controller. The benefit of MVC becomes less apparent because my file contains several hundred lines of code and is difficult to follow.

All examples I see show one controller per domain object such as Person. It feel like I should have a PersonManagement controller for AddPerson, DeletePerson, EditPerson and a BossManagement controller for AddPersonBoss, RemovePersonBoss.

Does this make sense? Why would I not want to break it into several controllers? Too many action in one controller becomes difficult, but all examples I see do this.

Sergey K.
  • 24,894
  • 13
  • 106
  • 174
Bawss
  • 1

2 Answers2

0

I would suggest to use both approaches, because sometimes it is a bit difficult to use only one particular approach. If controller is growing significanly then consider to split it into multiple partial classes.

ShahidAzim
  • 1,446
  • 1
  • 10
  • 15
0

that is depend on your application

i prefer to make a controller for each operation because that makes my controller code simple

but if you have a lot of operations that will lead to creating a lot of files for each

controller so then you have to make one file to group some controllers together to make the

application simpler

Muhamad Bhaa Asfour
  • 1,075
  • 3
  • 22
  • 39