Better to have huge Controllers, or many controllers, in MVC?

后端 未结 7 1179
-上瘾入骨i
-上瘾入骨i 2021-01-30 01:23

We are building a fairly large HR application in ASP.NET MVC, and so far our controllers are becoming quite large. For example, we have an Employee controller, and all employee

7条回答
  •  有刺的猬
    2021-01-30 02:06

    Partial classes allow you to spread your class across multiple files. That way you can group relevant areas of your controller into separate files, and yet they'll all still be part of the same controller. e.g.

    EmployeeDeductionController.cs

    public partial class EmployeeController
    {
        public ActionResult Deduct()
        {
        }
        // etc
    }
    

    EmployeeBenefitController.cs

    public partial class EmployeeController
    {
        public ActionResult GiveBenefit()
        {
        }
        // etc
    }
    

提交回复
热议问题