Example of Default Functionalities in ASP.NET MVC Form Renderer Control
The FormRenderer is a powerful, schema-driven component that enables you to build and render complex forms with ease using a structured definition. This sample showcases the Form Renderer component with an intuitive property panel, allowing you to seamlessly switch between predefined forms and explore its capabilities.
Registration Form
Customer Service Request
Doctor Appointment
@Html.UiFormRenderer(new UiFormRendererOptions { Id = form.Id, Columns = 2, SubmitText = form.Submit, OnSubmit = "onFormSubmit", Fields = (List<UiFormField>)ViewData[form.Key] })
@Html.UiRadioButton("formSchemaOption", "userRegistration", true, new UiRadioButtonOptions { Id = "radio1", Label = "User Registration", OnChange = "changeSchema" })
@Html.UiRadioButton("formSchemaOption", "customerService", false, new UiRadioButtonOptions { Id = "radio2", Label = "Customer Service", OnChange = "changeSchema" })
@Html.UiRadioButton("formSchemaOption", "doctorsAppointment", false, new UiRadioButtonOptions { Id = "radio3", Label = "Doctor Appointment", OnChange = "changeSchema" })
@{
var forms = new[]
{
new { Key = "userRegistration", Id = "form-renderer-control", Title = "Registration Form", Submit = "Submit" },
new { Key = "customerService", Id = "form-renderer-customer", Title = "Customer Service Request", Submit = "Submit Request" },
new { Key = "doctorsAppointment", Id = "form-renderer-doctor", Title = "Doctor Appointment", Submit = "Book Appointment" }
};
}
<div class="fr-demo control-section">
<div class="control-wrapper fr-forms">
@foreach (var form in forms)
{
<div id="fr-@form.Key" class="fr-form"@(form.Key == "userRegistration" ? "" : " hidden")>
<div class="form-title"><h1>@form.Title</h1></div>
<hr />
@Html.UiFormRenderer(new UiFormRendererOptions { Id = form.Id, Columns = 2, SubmitText = form.Submit, OnSubmit = "onFormSubmit", Fields = (List<UiFormField>)ViewData[form.Key] })
</div>
}
<div id="fr-result" class="fr-result" role="status" aria-live="polite"></div>
</div>
<div id="form-renderer-panel" class="demo-property-panel property-section" title="Select a ready-to-use form template">
<div>@Html.UiRadioButton("formSchemaOption", "userRegistration", true, new UiRadioButtonOptions { Id = "radio1", Label = "User Registration", OnChange = "changeSchema" })</div>
<div>@Html.UiRadioButton("formSchemaOption", "customerService", false, new UiRadioButtonOptions { Id = "radio2", Label = "Customer Service", OnChange = "changeSchema" })</div>
<div>@Html.UiRadioButton("formSchemaOption", "doctorsAppointment", false, new UiRadioButtonOptions { Id = "radio3", Label = "Doctor Appointment", OnChange = "changeSchema" })</div>
</div>
</div>
<style>
.fr-demo .fr-forms { max-width: 760px; margin: 0 auto; padding: 16px 0; }
.fr-demo .form-title h1 { margin: 0 0 8px; font-size: 22px; }
.fr-demo .fr-result { margin-top: 14px; font-size: 13px; }
.fr-demo .fr-form[hidden] { display: none; }
.fr-demo #form-renderer-panel > div { padding: 6px 0; }
</style>
<script>
// Syncfusion: the radio buttons of the property panel give the Form Renderer one of three ready-to-use forms
function changeSchema(value) {
['userRegistration', 'customerService', 'doctorsAppointment'].forEach(function (key) { document.getElementById('fr-' + key).hidden = key !== value; });
document.getElementById('fr-result').textContent = '';
}
// Submit shows what was entered, instead of posting it
function onFormSubmit(args) {
document.getElementById('fr-result').textContent = 'Submitted: ' + JSON.stringify(args.values);
args.cancel = true;
}
// Customer Service: the category follows the request type, and waits for one
var categories = {
'Technical Support': ['Bug', 'Configuration', 'Performance', 'Access Issue'],
'Billing': ['Invoice', 'Payment Failure', 'Refund', 'Subscription'],
'General Inquiry': ['Product Information', 'Pricing', 'Documentation'],
'Feature Request': ['New Feature', 'Enhancement', 'Integration']
};
function items(list) { return list.map(function (v) { return { value: v, text: v }; }); }
function follow(id, list) {
var box = window.Lumen.get(id);
box.setItems(items(list || []));
box.setValue(null);
box[list && list.length ? 'enable' : 'disable']();
}
function requestTypeChange(value) { follow('form-renderer-customer_Category', categories[value]); }
// Doctor Appointment: the doctor follows the department; the insurance fields follow the answer
var doctors = {
'Cardiology': ['Dr. John Carter', 'Dr. Emily Smith'],
'Dermatology': ['Dr. Sarah Wilson', 'Dr. Michael Brown'],
'Pediatrics': ['Dr. David Lee', 'Dr. Lisa Thomas'],
'Orthopedics': ['Dr. Robert Taylor', 'Dr. James Walker']
};
function departmentChange(value) { follow('form-renderer-doctor_Doctor', doctors[value]); }
function insuranceChange(value) {
['InsuranceProvider', 'PolicyNumber'].forEach(function (name) {
var field = document.querySelector('#form-renderer-doctor .ui-form-field[data-field="' + name + '"]');
var box = window.Lumen.get('form-renderer-doctor_' + name);
field.hidden = value !== 'Yes';
if (box) { box[value === 'Yes' ? 'enable' : 'disable'](); }
});
}
window.addEventListener('load', function () { insuranceChange('No'); });
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class FormRendererController : Controller
{
// The page is Views/FormRenderer/Default.cshtml; it draws what ViewData holds.
public ActionResult Default()
{
ViewData["userRegistration"] = new FormRendererData().GetUserRegistration();
ViewData["customerService"] = new FormRendererData().GetCustomerService();
ViewData["doctorsAppointment"] = new FormRendererData().GetDoctorsAppointment();
return View();
}
/// <summary>The form definitions of the samples, as Syncfusion's FormRendererData holds them (fields with their labels, rules and choices).</summary>
public class FormRendererData
{
private static List<UiListItem> Items(params string[] values)
{
return values.Select(v => new UiListItem { Value = v, Text = v }).ToList();
}
/// <summary>The User Registration form: personal information and account details.</summary>
public List<UiFormField> GetUserRegistration()
{
return new List<UiFormField>
{
new UiFormField { Name = "FirstName", Label = "First Name", Required = true },
new UiFormField { Name = "LastName", Label = "Last Name", Required = true },
new UiFormField { Name = "PhoneNumber", Label = "Phone Number", Type = UiFormFieldType.Number, Placeholder = "Enter your phone number", Options = new { ShowSpinButton = false, Format = "N0" } },
new UiFormField { Name = "UserName", Label = "User Name", Required = true },
new UiFormField { Name = "Password", Label = "Password", Type = UiFormFieldType.Password, Required = true },
new UiFormField { Name = "ConfirmPassword", Label = "Confirm Password", Type = UiFormFieldType.Password, Required = true },
new UiFormField { Name = "Terms", Label = "I agree to the Terms and Conditions", Type = UiFormFieldType.CheckBox, Columns = 12 }
};
}
/// <summary>The Customer Service form: the customer and the request (the category follows the request type).</summary>
public List<UiFormField> GetCustomerService()
{
return new List<UiFormField>
{
new UiFormField { Name = "CustomerName", Label = "Customer Name", Required = true, Placeholder = "Enter your full name" },
new UiFormField { Name = "EmailAddress", Label = "Email Address", Type = UiFormFieldType.Email, Placeholder = "Enter your email" },
new UiFormField { Name = "PhoneNumber", Label = "Phone Number", Type = UiFormFieldType.Number, Placeholder = "Enter your phone number", Options = new { ShowSpinButton = false, Format = "N0" } },
new UiFormField { Name = "RequestType", Label = "Request Type", Type = UiFormFieldType.DropDown, Options = new { OnChange = "requestTypeChange" }, Required = true, Placeholder = "Enter the request type",
Items = Items("Technical Support", "Billing", "General Inquiry", "Feature Request") },
new UiFormField { Name = "Category", Label = "Category", Type = UiFormFieldType.DropDown, Required = true, Placeholder = "Choose a request type first", Disabled = true,
Items = Items("Bug", "Configuration", "Performance", "Access Issue", "Invoice", "Payment Failure", "Refund", "Subscription", "New Feature", "Enhancement", "Integration", "Product Information", "Pricing", "Documentation") },
new UiFormField { Name = "Priority", Label = "Priority", Type = UiFormFieldType.DropDown, Required = true, Placeholder = "Enter the priority of the issue",
Items = Items("Low", "Medium", "High", "Critical") },
new UiFormField { Name = "Description", Label = "Description", Type = UiFormFieldType.TextArea, Required = true, Placeholder = "Enter the description", Columns = 12 }
};
}
/// <summary>The Doctor Appointment form: the patient, the appointment and the healthcare information (the doctor follows the department; the insurance fields follow the answer).</summary>
public List<UiFormField> GetDoctorsAppointment()
{
return new List<UiFormField>
{
new UiFormField { Name = "PatientName", Label = "Patient Name", Required = true },
new UiFormField { Name = "EmailAddress", Label = "Email Address", Type = UiFormFieldType.Email, Required = true },
new UiFormField { Name = "MobileNumber", Label = "Mobile Number", Required = true },
new UiFormField { Name = "Gender", Label = "Gender", Type = UiFormFieldType.DropDown, Required = true, Items = Items("Male", "Female", "Other") },
new UiFormField { Name = "Age", Label = "Age", Type = UiFormFieldType.Number, Options = new { Min = 0, Max = 120, Format = "N0" } },
new UiFormField { Name = "DateOfBirth", Label = "Date of Birth", Type = UiFormFieldType.Date, Required = true },
new UiFormField { Name = "Department", Label = "Department", Type = UiFormFieldType.DropDown, Options = new { OnChange = "departmentChange" }, Required = true, Items = Items("Cardiology", "Dermatology", "Pediatrics", "Orthopedics") },
new UiFormField { Name = "Doctor", Label = "Doctor", Type = UiFormFieldType.DropDown, Required = true, Disabled = true, Placeholder = "Choose a department first",
Items = Items("Dr. John Carter", "Dr. Emily Smith", "Dr. Sarah Wilson", "Dr. Michael Brown", "Dr. David Lee", "Dr. Lisa Thomas", "Dr. Robert Taylor", "Dr. James Walker") },
new UiFormField { Name = "AppointmentDate", Label = "Appointment Date", Type = UiFormFieldType.Date, Required = true },
new UiFormField { Name = "AppointmentTime", Label = "Appointment Time", Type = UiFormFieldType.DropDown, Required = true, Items = Items("09:00 AM", "10:00 AM", "11:00 AM", "02:00 PM", "03:00 PM", "04:00 PM") },
new UiFormField { Name = "VisitType", Label = "Visit Type", Type = UiFormFieldType.Radio, Required = true, Columns = 12, Items = Items("Consultation", "Follow-up", "Routine Checkup", "Emergency") },
new UiFormField { Name = "ReasonForVisit", Label = "Reason for Visit", Type = UiFormFieldType.TextArea, Required = true, Columns = 12 },
new UiFormField { Name = "HasInsurance", Label = "Has Insurance", Type = UiFormFieldType.Radio, Options = new { OnChange = "insuranceChange" }, Columns = 12, Items = Items("Yes", "No") },
new UiFormField { Name = "InsuranceProvider", Label = "Insurance Provider", Required = true },
new UiFormField { Name = "PolicyNumber", Label = "Policy Number", Required = true }
};
}
/// <summary>The Contact Us form of the Custom Components sample.</summary>
public List<UiFormField> GetContactForm()
{
return new List<UiFormField>
{
new UiFormField { Name = "fullName", Label = "Full Name", Type = UiFormFieldType.Custom, Component = "customText", Required = true, Options = new { Placeholder = "Enter your full name" }, Validation = new UiFormValidation { MinLength = 2, MaxLength = 100 }, Columns = 12 },
new UiFormField { Name = "email", Label = "Email Address", Type = UiFormFieldType.Custom, Component = "customEmail", Required = true, Options = new { Placeholder = "Enter your email address" }, Columns = 12 },
new UiFormField { Name = "inquiryType", Label = "Inquiry Type", Type = UiFormFieldType.Custom, Component = "customDropdown", Columns = 12,
Options = new { Placeholder = "Select inquiry type", Items = new[] { new { Text = "General Inquiry", Value = "general" }, new { Text = "Sales", Value = "sales" }, new { Text = "Support", Value = "support" }, new { Text = "Partnership", Value = "partnership" }, new { Text = "Feedback", Value = "feedback" } } } },
new UiFormField { Name = "message", Label = "Message", Type = UiFormFieldType.Custom, Component = "customTextarea", Required = true, Options = new { Placeholder = "Enter your message", Rows = 5 }, Validation = new UiFormValidation { MinLength = 10, MaxLength = 1000 }, Columns = 12 },
new UiFormField { Name = "consent", Label = "Consent", Type = UiFormFieldType.Custom, Component = "customCheckbox", Required = true, Options = new { Text = "I agree to be contacted regarding my inquiry." }, Columns = 12 }
};
}
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
In this sample, multiple ready-to-use form templates—such as User Registration, Customer Service, and Doctor Appointment—are displayed in the property panel using radio buttons. Select any option to instantly apply the corresponding form definition to the Form Renderer component.
Each form can be filled out interactively and submitted for data collection, demonstrating how the component streamlines form creation, customization, and data capture in real-world scenarios.
Design custom forms visually and export their schema in seconds with our interactive Form Builder — a powerful no-code tool for building responsive forms through an intuitive drag-and-drop interface.