Introduction
This article shows how to create a Checkbox List. In this application we create a dropdown list of checkboxes in which we can select one or more records.
Now let's see the application
Step 1
Use the following procedure to create the sample application using the Web API:
- Start Visual Studio 2013.
- From the Start Window select "New Project".
- Select "Installed" -> "Templates" -> "Visual C#" -> "Web" -> "Visual Studio 2012" and select "ASP.NET MVC4 Web Application".

- Click on the "OK" button.
- From the MVC4 project window select "Web API".

- Click on the "OK" button.
Step 2
Use the following procedure to create a Model class:
- In the "Solution Explorer".
- Right-click on the Model Folder.
- Select "Add" -> "Class".
- Select "Installed" -> "Visual C#" and select "Class".

- Click on the "OK" button.
Add the following Code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace CheckBoxlistAPI.Models
- {
- public class User
- {
- public IList<SelectListItem> User_Name { get; set; }
- }
- }
Step 3
Use the following procedure to create a Controller:
- In the "Solution Explorer".
- Right-click on the "Controller Folder".
- Select "Add" -> "Controller".

- Select "MVC Controller" from the template.
- Click on the "Add" button.
Add the following Code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using CheckBoxlistAPI.Models;
- namespace CheckBoxlistAPI.Controllers
- {
- public class UsersController : Controller
- {
- //
- // GET: /Users/
- public ActionResult Index()
- {
- return View();
- }
- public ActionResult UserView()
- {
- User obj = new User();
- List<SelectListItem> Username = new List<SelectListItem>();
- Username.Add(new SelectListItem{Text = "User1", Value="1"});
- Username.Add(new SelectListItem{Text ="User2",Value="2"});
- Username.Add(new SelectListItem { Text = "User3", Value = "3" });
- Username.Add(new SelectListItem { Text = "User4", Value = "4" });
- obj.User_Name = Username;
- return View(obj);
- }
- }
- }




Join the conversation! Your thoughts help the community grow.