Search results

Getting Started

This section briefly explains about how to include a simple RadioButton in your ASP.NET MVC application. You can refer ASP.NET MVC Getting Started documentation page for introduction part of the system requirements and configure the common specifications.

Add RadioButton to the project

We are going to render RadioButton component in Index.cshtml page.

razor
default.cs
@Html.EJS().RadioButton("radio1").Label("Option 1").Name("default").Render()
@Html.EJS().RadioButton("radio2").Label("Option 2").Name("default").Render()
public IActionResult Index()
    {
            return View();
    }

Output be like the below.

RadioButton Sample

Run the application

After successful compilation of your application, simply press F5 to run the application.

The following example shows a default rendering of RadioButton.

razor
default.cs
@Html.EJS().RadioButton("radio1").Label("Option 1").Name("default").Render()
@Html.EJS().RadioButton("radio2").Label("Option 2").Name("default").Render()
public IActionResult Index()
    {
            return View();
    }

Change the RadioButton state

The Essential JS 2 RadioButton contains 2 states visually, they are as follows:

  • Checked
  • Unchecked

The RadioButton checked property is used to handle the checked and unchecked state. In the checked state an inner circle will be added to the visualization of RadioButton.

razor
state.cs
@Html.EJS().RadioButton("radio1").Label("Option 1").Name("state").Checked(true).Render()
@Html.EJS().RadioButton("radio2").Label("Option 2").Name("state").Render()
public IActionResult state()
    {
            return View();
    }