Bug tracker: Create the ProjectController class

The Project controller contains the logic for the actions that you want to perform against the Project content type. In this tutorial, the projects are only displayed in the frontend. While in the AreaRegistration class, you defined the default action as Index.  The Index action thus returns a view populated with the available projects.

To create a controller for the Project content type:

  1. In Visual Studio, navigate to Areas » BugTracker » Controllers folder and create a new class.
    Name the class ProjectController.
  2. Make your class inherit the Controller class.
    The Controller class is located in the System.Web.Mvc namespace.
  3. Create a method to query all available projects.
    The method returns all available projects using an IQueryable. For more information how to query objects of your dynamic content type, you can refer to the generated documentation for your custom module. You can view it in the backend, on the page for configuring your custom module.
  4. Create an Index action:
    1. Create a method named Index.
    2. As a return type specify ActionResult.
    3. Call the View method of the Controller class and pass the name of the desired view (in this case “ProjectMaster”) as the viewName argument and the query for the available projects as the model argument.
    4. Return the result of the View method.

GITHUB EXAMPLE: For more information about the content of the file, see the ProjectController.cs file of the downloaded sample project.

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?