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:
- In Visual Studio, navigate to Areas » BugTracker » Controllers folder and create a new class.
Name the class ProjectController.
- Make your class inherit the Controller class.
The Controller class is located in the System.Web.Mvc namespace.
- 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.
- Create an Index action:
- Create a method named Index.
- As a return type specify ActionResult.
- 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.
- 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.