You use MVC form fields to collect user input and persist the input in form responses. MVC form fields follow the model-view-controller convention, so you create form fields in a similar workflow as creating widgets in MVC. In addition, similar to standard form fields, you can create the new fields in separate assemblies, following MVC principles of "separation of concerns".
The following tutorial demonstrates how to create a Yes/No field to use in MVC forms. You first create the folder structure, then the custom model, controller, and view. Finally, you register the field in Sitefinity CMS forms toolbox.
The model represents the data your application works with.
NOTE: This example uses plain C# classes for the model.
To create the custom model:
NOTE: When creating new form fields, your controller can inherit FormFieldControllerBase. Thus, your field is compatible with the forms functionality in Sitefinity CMS. The FormFieldControllerBase provides two actions - Write and Read, which are invoked depending on the Form widget settings. If you want to implement some custom logic in these actions, you can just override them.
You implement the view that shows the data from the model, populated in the controller:
This tutorial assumes that you are directly changing your Sitefinity CMS project. However, you may also use a separate assembly to contain your custom code. If you do so, add reference to your custom assembly in your Sitefinity CMS project.
After you complete adding the code for your custom form fields, and, if needed, add references to your assembly, as a final step you need to build your solution.
RESULT: The field is automatically registered in Sitefinity CMS forms toolbox and you can now use the new field on your MVC forms.
After you have created and registered the custom form field, you can apply rules to it by following procedure Extend form rules procedure.
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important
Copyright © 2022 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.
Progress, Telerik, Ipswitch, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.
Powered by Progress Sitefinity