Mvc check boxes

How to show checkbox selected items in MVC?

We can show checkbox items from multiple items whatever we select.

Cshtml Page:

  <h4>Select Preferred work location</h4> 
 for (inti = 0; i<Model.Cities.Count; i++) 
 @using (Html.BeginForm()) 
 @Html.CheckBoxFor(m =>Model.Cities[i].IsChecked) 
 @Html.HiddenFor(m =>Model.Cities[i].Value) 
 @Html.HiddenFor(m =>Model.Cities[i].Text)<br/> 
 <divclass="col-md-offset-2 col-md-10"> 


Controller Page:

publicActionResult Index()
 //Add Records into generic list
  List<CityModel>obj = new List<CityModel>() 
 newCityModel {Text="Swimming",Value=1,IsChecked=false }, 
 newCityModel {Text="Sketting",Value=2,IsChecked=true }, 
 newCityModel {Text="Painting",Value=2,IsChecked=false }, 
 newCityModel {Text="PalyingCricket",Value=2,IsChecked=false }, 
 CityListobjBind = newCityList(); 
 objBind.Cities = obj; 
 return View(objBind); 

Leave a comment

Your email address will not be published. Required fields are marked *