Checkbox control in MVC
In this article I am 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;
public class ModelClass
public List<string> Hobbies
List<string> hobby = new List<string>();
After completing the section of Model, here in the Controller class I have created two Action methods. First Index method that return a View along with the object of ModelClass and in the second action method i.e. Show which check the state of checkbox and stores selected checkbox value in a variable.
public class HomeController : Controller
public ActionResult Index()
return View(new ModelClass());
public string Show(FormCollection postedForm, ModelClass model)
string val = "";
foreach (var category in model.Hobbies)
val = val + " " + category;
return "Selcted hobbies are: <b>" + val + "</b>";
After performing the above tasks, you have to create the checkbox in a View which displays the hobby that is return by a property of Model. Also create a submit button on click of which selected hobbies are displayed or we can say selected checkboxes values are displayed.
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<CheckBoxMVC.Models.ModelClass>" %>
<% using (Html.BeginForm("Show", "Home", FormMethod.Post))
<b>Select Hobbies : </b>
<% foreach (string hobby in Model.Hobbies)
<%: Html.CheckBox(hobby)%><%: hobby%>
<br /><br />
<input type="submit" value="Submit" />
After performing the above tasks, we can see the output of our application in a browser with the multiple checkboxes.
When a submit button is pressed selected hobbies are displayed.
By using above process you can simply learn that how to create checkbox and get a selected checkbox value in MVC.