Search code examples
asp.net-mvcasp.net-mvc-4splitcontrollers

Different controllers for views on the same folder on asp.net MVC4


I've been researching about this. I found "MVCs areas" but I still couldn't do what I'm looking for.

MY VIEWS: Views/ Student/Course Student/Information Student/Status Student/GeneralSituation etc, etc...

CONTROLLERS:

Controllers/Student

What I want to do is:

I don't want to have All the code from a lot of views in just one "Student" controller. Any tip regarding how I can "split" my controllers in several files? I'm just looking at the simplest approach, I don't want to make big modifications to my project.

I'm using MVC4.

Thanks in advance!..

PnP


Solution

  • you can do a partial class StudentController:

    your folder/files would look like this:

    Controllers
      StudentController
        StudentController.Status.cs
        StudentController.GeneralSituation.cs
        StudentController.Course.cs
    

    The code would be:

    StudentController.Status.cs:

    public partial class StudentController
    {
        [Actions relevant for Status of a student]
    }
    

    StudentController.GeneralSituation.cs:

    public partial class StudentController
    {
        [Actions relevant for General Situation of a student]
    }