hello,
i have this comma seperated string a = 125, 253, 125 on page load i want to loop that if a value has in checkbox list so it should be checked on checbox list binding
i have this checkbox list binding,
@model List<MVCApp.Models.FirstCategories>
@using (@Html.BeginForm("CheckboxListTopcategoryMenu_post", "Application", FormMethod.Get))
{
<input type="hidden" id="checkedCheckBoxes" name="checkedHobbies" />
for (int i = 0; i < Model.Count(); i++)
{
@Html.HiddenFor(m => m[i].id)
@Html.HiddenFor(m => m[i].Title)
@Html.CheckBoxFor(m => m[i].isSelected)
@Html.DisplayFor(m => m[i].Title)
}
<input id="Button2" type="submit" class="btn red" value="Search" />
}
method to checkboxlist binding
public ActionResult CheckboxListTopcategoryMenu()
{
//Call first category in top category menu partial layout
//DataTable ds = new DataTable();
CategoriesBL fc = new CategoriesBL();
//ds = fc.SelectFirstCategoriesBL();
//Fille properties of contractIdetails
return PartialView("CheckboxListTopcategoryMenu", fc.GetCategoriesBL());
}
public ActionResult CheckboxListTopcategoryMenu_post(List<FirstCategories> categoryselected)
{
string _searches = "";
foreach (FirstCategories cat in categoryselected)
{
if (cat.isSelected)
{
_searches += cat.id.ToString() + ",";
}
}
string url = string.Format("/ads/search?search={0}", _searches);
return Redirect(url);
//return View();
}