CheckboxList

Custom Item Render

CheckboxList can get data from an Url, which must return a collection of KeyContent.
An additional parameter is sent to the Url using the Parameter extension.
Using a custom render function for the Item by setting ItemFunc property.
CheckboxList/Index.cshtml
    @(Html.Awe().CheckBoxList(new CheckBoxListOpt
{
Name = "Meals",
Url = Url.Action("GetMealsImgByCateg", "Data"),
ItemFunc = "site.imgItem"
}.Parameter("categories", DemoCache.Categories[0].Id)))
Awesome/DataController.cs
public IActionResult GetMealsImgByCateg(int[] categories)
{
var url = Url.Content(DemoUtils.MealsUrl);
categories = categories ?? new int[] { };

var items = mcx.Meals.Where(o => categories.Contains(o.Category.Id))
.Select(o => new MealDisplay(o.Id, o.Name, url + o.ImageName, o.Category.Id));

return Json(items);
}

Cascade

CheckboxList/Index.cshtml
    @(Html.Awe().RadioButtonList(new RadioButtonListOpt
{
Name = "CatDd",
Url = Url.Action("GetCategories", "Data"),
Value = DemoCache.Categories[2].Id
}))

@(Html.Awe().CheckBoxList(new CheckBoxListOpt
{
Name = "MealsDd",
AutoSelectFirst = true,
Url = Url.Action("GetMeals", "Data")
}.Parent("CatDd", "categories")))
Awesome/DataController.cs
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);
}

Toggle select all



CheckboxList/Index.cshtml
<div class="ib">
<button type="button" class="awe-btn" onclick="toggleChkl('chklCatAll')">toggle select all</button>
<br />
<br />
@(Html.Awe().CheckBoxList(new CheckBoxListOpt { Name = "chklCatAll", Url = Url.Action("GetCategories", "Data") }))
</div>
<script>
function toggleChkl(id) {
var f = $('#' + id).parent();
f.find(':checkbox').prop('checked', !f.find(':checkbox').first().prop('checked')).trigger('change');
}
</script>

Set value from get items call



setting selected items in the controller by returning AweItems instead of KeyContent[]



Comments