Search results

Getting Started

This section briefly explains about how to include a simple CheckBox 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 CheckBox to the project

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

razor
default.cs
@Html.EJS().CheckBox("default").Label("Default").Render()
public IActionResult Default()
    {
            return View();
    }

Output be like the below.

CheckBox 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 CheckBox.

razor
default.cs
@Html.EJS().CheckBox("default").Label("Default").Render()
public IActionResult Default()
    {
            return View();
    }

Change the CheckBox state

The Essential JS 2 CheckBox contains 3 different states visually, they are:

  • Checked
  • Unchecked
  • Indeterminate

The CheckBox checked property is used to handle the checked and unchecked state. In checked state a tick mark will be added to the visualization of CheckBox.

Indeterminate

The CheckBox indeterminate state can be set through indeterminate property. CheckBox indeterminate state masks the real value of CheckBox visually. The Checkbox cannot be changed to indeterminate state through the user interface, this state can be achieved only through the property.

razor
state.cs
@section ControlsSection{
    @Html.EJS().CheckBox("checked").Label("Checked State").Checked(true).Render()
    @Html.EJS().CheckBox("unchecked").Label("Unchecked State").Render()
    @Html.EJS().CheckBox("indeterminate").Label("Intermediate State").Intermediate(true).Render()
}

<style>

.e-checkbox-wrapper {
  margin-top: 18px;
}

li {
  list-style: none;
}

</style>
public IActionResult State()
    {
            return View();
    }