Search results

RadioButtonFor and Model Binding

This section demonstrates the Strongly typed extension support in RadioButton. The view that can bind with any model is called as strongly typed view. You can bind any class as model to view. You can access model properties on that view. You can use data associated with model to render the component.

In this sample, first check the male value and click the submit button to post the selected value in the RadioButton. When female value is checked, validation error message will be shown below the RadioButton.

@using Syncfusion.EJ2.Blazor.Buttons
@using System.ComponentModel.DataAnnotations

<EditForm Model="Annotate">
    <div class="form-group">
        <EjsRadioButton Label="Male" Name="Gender" Value="male" @bind-Checked="@Annotate.Gender"></EjsRadioButton>
        <EjsRadioButton Label="Female" Name="Gender" Value="female"></EjsRadioButton>
        <ValidationMessage For="@(() => Annotate.Gender)" />
    <EjsButton HtmlAttributes="@Submit" Content="Submit" IsPrimary="true"></EjsButton>

@code {

    public Annotation Annotate = new Annotation();

    public class Annotation
        [Range(typeof(bool), "true", "true", ErrorMessage = "Male gender is required.")]
        public bool Gender { get; set; }
    public Dictionary<string, object> Submit = new Dictionary<string, object>()
        { "type", "submit"}

Output be like

Radio Button Sample