Checkbox list in ASP.Net MVC


In this article I am going to explain you how to build the CheckBoxList control in ASP.NET MVC using the basic control and Razor engine. The read should have the basic knowledge of ASP.NET MVC framework.

The resource has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this resource.
This resource will be reviewed shortly.
If you think this resource contain inappropriate content, please report to webmaster.
Recently, I got an assignment when I need to show the items in checkbox list format. It was very easy in ASP.NET web form because it has CheckBoxList control but it was bit challenging for me to show the items in checkbox list in ASP.NET MVC as there are basic controls available.

In this post I am going to explain you how to build the CheckBoxList control in ASP.NET MVC using the basic control and Razor engine following the steps listed below. Let's get started

Step 1. First thing first, View Code

@model SOW.Models.DropdownValues





Select Country:

@foreach (var item in Model.SendingCountryList)
{



}



Step 2. Model
public class DropdownValues
{
public DropdownValues()
{
CountryList = new List();
}
public IList SendingCountryList { get; set; }
}

Step 3. Controller – Create a controller name CheckboxListController
public class CheckboxListController : Controller
{
// GET: AnnualReview
public ActionResult CheckboxList()
{
DropdownValues dv = new DropdownValues();
//Sending Country List
dv.CountryList.Add(new SelectListItem { Text = "Select All", Value = "SelectAll" });
dv. CountryList.Add(new SelectListItem { Text = "Australia Australia Australia Australia", Value = "Australia" });
dv. CountryList.Add(new SelectListItem { Text = "Austria", Value = "Austria" });
return View("ViewName", dv);

}
}

Step 4. Final Output

img


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: