Bug tracker: Create the BugController class

After you create the ProjectController class, you create the BugController class. The bug controller contains the logic for the actions that you want to perform against the Bug content type. In this tutorial, the bugs are displayed and created in the frontend. The Index action returns a view populated with the available bugs for a specified project. The Create action creates a Bug item and stores it in the database. Note that in this step only the Index action is created.

To create a controller for the Bug content type:

  1. In Visual Studio, navigate to the Areas » BugTracker » Controllers folder, create a new class.
    Name the class BugController.
  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 bugs from a specific project.
    The method returns all available bugs form a specified project using an IQueryable. For more information how to query objects of your dynamic content type, you can refer to the generated documentation of your custom module. You can find it in the backend, on the page for configuring your custom module.
  4. Create an Index action:
    1. Create a method and name it Index.
    2. As a return type specify ActionResult.
      The URL triggering this action will contain the ID of the live version of the specified project.
    3. Get the ID of the master version of the specified project by geting an instance of the live version of the project.
      The ID of the master version is stored in the OriginalContentId property.
    4. Call the View method of the Controller class and pass the name of the desired view (in this case, BugMaster) and the query for the available bugs.
      The query will be assigned to the Model property of the view.
    5. Return the result of the View method.

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

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?