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.
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(mcx.Categories.Select(o => new KeyContent(o.Id, o.Name)));
}

public IActionResult GetMeals(int[] categories)
{
categories = categories ?? new int[] { };
var items = mcx.Meals.Where(o => categories.Contains(o.Category.Id))
.Select(o => new KeyContent(o.Id, o.Name));

return Json(items);
}

Using predefined parameters

setting parameter parent = { Fruits, Legumes } using .Parameter and .ParameterFunc extensions



Comments