---
title: "Checkbox control in MVC"  
description: "The Checkbox control in MVCHere, In this Article, We are going to explain how to create checkbox control and how to get the selected checkboxes valu"  
author: "Chris Anderson"  
published: 2011-10-03  
updated: 2020-08-05  
canonical: https://www.mindstick.com/articles/759/checkbox-control-in-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 3 minutes  

---

# Checkbox control in MVC

## The Checkbox control in MVC

Here, In this Article, We are going to explain how to create checkbox control and how to get the selected checkboxes value in MVC.

Here in the Model class, I have created a property named Hobbies that is of type **List<string>**, that return some natural hobbies such as Cricket, Football, Hockey stored in a property as I have mentioned below;

```
using System.Collections.Generic;using System.Web;
namespace CheckBoxMVC.Models{
     public class ModelClass    {         public List<string> Hobbies         {
            get            {                List<string> hobby = new List<string>();                hobby.Add("Cricket");                hobby.Add("Football");                hobby.Add("Hockey");                return hobby;
            }
        }
    }
}
```

After completing the section of Model, here in the Controller class, I have created two Action methods.

First Index method that returns a View along with the object of ModelClass and in the second action method i.e.

The show which checks the state of checkbox and stores selected [checkbox value](https://www.mindstick.com/articles/1385/editable-grid-view-system-using-bootstrap-in-asp-dot-net) in a variable.\

```
using System.Collections.Generic;using System.Web;using System.Web.Mvc;using CheckBoxMVC.Models;
namespace CheckBoxMVC.Controllers{
     public class HomeController : Controller    {
         public ActionResult Index()         {            return View(new ModelClass());         }
         [HttpPost]         public string Show(FormCollection postedForm, ModelClass model)         {
            string val = "";            foreach (var category in model.Hobbies)            {
                if (postedForm[category].ToString().Contains("true"))                {                    val = val + " " + category;                }            }            return "Selcted hobbies are: <b>" + val + "</b>";
         }
    }
}
```

After performing the above tasks, you have to create the [checkbox](https://www.mindstick.com/articles/12740/checkbox-in-android) in a View which displays the hobby that is returned by a property of Model.

Also, create a submit button on click of which selected hobbies are displayed or we can say [selected checkboxes](https://www.mindstick.com/articles/1562/checkboxlist-example-in-asp-dot-net-mvc-4) values are displayed.

```
 <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<CheckBoxMVC.Models.ModelClass>" %>
<!DOCTYPE html><html>
<head runat="server">     <title>Index</title></head><body>
     <% using (Html.BeginForm("Show", "Home", FormMethod.Post))       { %>     <div>         <b>Select Hobbies : </b>         <% foreach (string hobby in Model.Hobbies)           { %>         <%: Html.CheckBox(hobby)%><%: hobby%>         <%} %>         <br /><br />         <input type="submit" value="Submit" />     </div>     <%} %></body></html>
```

After performing the above tasks, we can see the output of our application in a browser with multiple checkboxes.\

![Checkbox control in MVC](https://www.mindstick.com/mindstickarticle/2ee905ba-aea1-4d83-a49d-d8d8fb10c747/images/3a601a2e-2e88-416c-8029-0017b37894b9.png)

**When a submit button is pressed selected hobbies are displayed.**

![Checkbox control in MVC](https://www.mindstick.com/mindstickarticle/2ee905ba-aea1-4d83-a49d-d8d8fb10c747/images/2cb3101a-05d7-4306-b681-678deec17a3b.png)

By using the above process you can simply learn how to create a checkbox and get selected checkbox value in MVC.

---

Original Source: https://www.mindstick.com/articles/759/checkbox-control-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
