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:
- Create a
SaveBugmethod:- In the
BugControllerclass, create a new method and name itSaveBug. - As a return type specify
ActionResult. - Make the method accept an argument of type
BugModel.
- In the
- Mark the method with the
HttpPostattribute.
You do this because you will be triggering this action in aPOSTrequest, you must mark the action with this attribute. - 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 theOriginalContentIdproperty. - Create a new
Bugcontent item:- Call the
CreateDataItemmethod of theDynamicModuleManagerinstance. - Pass the type of the
Bugcontent 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.
- Call the
- Set the properties of the
Buginstance.
TheBugModelargument will contain the values from the form.- Set the properties of the
Bugcontent item to the appropriate values of theBugModelinstance. - Set the
UrlNameand theApprovalWorkflowStateproperties. The workflow state of the item must beDraft.
After an admin publishes it, it will be visible in the frontend.
- Set the properties of the
- Save the changes to the
DynamicModuleManagerinstance. - Redirect to the
BugMasterview by using theRedirectToActionmethod of theControllerclass. - Redirect to the
Indexaction of theBugControllerclass.
GITHUB EXAMPLE: For more information about the
SaveBugandSaveBugWorkermethods, 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.