Create non-input visual form elements

When working with MVC forms in Sitefinity CMS, you can take advantage of helper elements. You can drop elements on your form just like the standard form fields, but unlike fields, elements are not meant to collect user input. By default, there are a few build-in elements in the standard toolset, for example, Recaptcha and Section header.

The following tutorial demonstrates how to create a new MVC form element for displaying text content that is read-only. You first create the folder structure, then the custom model, controller, and view and finally register the element in Sitefinity CMS toolbox.

  1. Create the custom model.
    The model represents the data your application works with.

    NOTE: This example uses plain C# classes for the model.

    To create the custom model, perform the following:

    1. In the Models folder, create a new class and name it TextMessageModel.
    2. Open the TextMessageModel.cs file and paste the following code:
  2. Create the controller.
    In the Controllers folder, create a new class and name it TextMessageController.

    NOTE: When creating new form elements, your controller can inherit FormElementControllerBase. Thus, you do not have to implement specific methods needed to display the element in the form. The FormElementControllerBase provides two actions - Write and Read, which are invoked depending on the Form widget settings. If your custom element does not have one of these modes, you can override the particular action and redirect to the other.

  3. Create the view for the element Read mode.
    In the ~/Mvc/Views/TextMessage folder, create a new code file and name it Read.Default.cshtml. In this file, you implement the view that shows the data from the model, populated in the controller:

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?