Create the SaveBug action

After you create the CreateBug action, you create the SaveBug action that creates an instance of the Bug content type and saves it in the database. You must add this action to the BugController class. To do this:

  1. Create a SaveBug method:
    1. In the BugController class, create a new method and name it SaveBug.
    2. As a return type specify ActionResult.
    3. Make the method accept an argument of type BugModel.
  2. Mark the method with the HttpPost attribute.
    You do this because you will be triggering this action in a POST request, you must mark the action with this attribute.
  3. Get the master ID of the parent project.
    The URL triggering this action will contain the ID of the live version of the specified project. To get the master ID, get an instance of the live version of the project. The ID of the master version is stored in the OriginalContentId property.
  4. Create a new Bug content item:
    1. Call the CreateDataItem method of the DynamicModuleManager instance.
    2. Pass the type of the Bug content item. You can find the exact type of the Bug content item in its auto-generated documentation. You can find the documentation on the module’s backend page in the module builder.
  5. Set the properties of the Bug instance.
    The BugModel argument will contain the values from the form.
    1. Set the properties of the Bug content item to the appropriate values of the BugModel instance.
    2. Set the UrlName and the ApprovalWorkflowState properties. The workflow state of the item must be Draft.
      After an admin publishes it, it will be visible in the frontend.
  6. Save the changes to the DynamicModuleManager instance.
  7. Redirect to the BugMaster view by using the RedirectToAction method of the Controller class.
  8. Redirect to the Index action of the BugController class.

GITHUB EXAMPLE: For more information about the SaveBug and SaveBugWorker methods, 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.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its 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 .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?