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:
- In Visual Studio, navigate to the Areas » BugTracker » Controllers`` folder, create a new class.
Name the classBugController. - Make your class inherit the
Controllerclass.
TheControllerclass is located in theSystem.Web.Mvcnamespace. - Create a method to query all available bugs from a specific project.
The method returns all available bugs form a specified project using anIQueryable. 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. - Create an
Indexaction:- Create a method and name it
Index. - As a return type specify
ActionResult.
The URL triggering this action will contain the ID of the live version of the specified project. - 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 theOriginalContentIdproperty. - Call the
Viewmethod of theControllerclass 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 theModelproperty of the view. - Return the result of the
Viewmethod.
- Create a method and name it
GITHUB EXAMPLE: For more information about the content of the file, see the BugController.cs file of the downloaded sample project.
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. 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 ASP.NET Core and take advantage of its decoupled architecture and modern development model.