AjaxCheckBoxList
Cascading CheckboxList using binding to parent
The AjaxCheckboxList renders a list of checkboxes,
needs an url, js func or controller defined to get data from.
It can be bound to parent controls.
It can be bound to parent controls.
AjaxCheckboxListDemo/Index.cshtml
<h2>Cascading CheckboxList using binding to parent</h2>
@(Html.Awe().AjaxCheckboxListFor(o => o.ParentCategory)
.Url(Url.Action("GetCategories", "Data")))
@(Html.Awe().AjaxCheckboxListFor(o => o.ChildMeals)
.Parent(o => o.ParentCategory, "categories")
.Url(Url.Action("GetMeals", "Data")))
Awesome/DataController.cs
public IActionResult GetCategories()
{
return Json(Db.Categories.Select(o => new KeyContent(o.Id, o.Name)));
}
public IActionResult GetMeals(int[] categories)
{
categories = categories ?? new int[] { };
var items = Db.Meals.Where(o => categories.Contains(o.Category.Id))
.Select(o => new KeyContent(o.Id, o.Name));
return Json(items);
}
Select all option
Setting SelectAll option to get a checkbox that will toggle select/unselect all items
AjaxCheckboxListDemo/Index.cshtml
@(Html.Awe().AjaxCheckboxList("SelectAllOptChkl")
.SelectAll()
.Url(Url.Action("GetCategories", "Data")))
Using predefined parameters
setting parameter parent = { Fruits, Legumes } using .Parameter and .ParameterFunc extensions
Comments