RadioButtonList

Basic usage

RadioButtonList can get data from an Url, the Url must return a collection of KeyContent.
RadioButtonList/Index.cshtml
@(Html.Awe().RadioButtonList(new RadioButtonListOpt
{
Name = "Cats",
Url = Url.Action("GetCategories", "Data")
}))
Awesome/DataController.cs
public IActionResult GetCategories()
{
return Json(Db.Categories.Select(o => new KeyContent(o.Id, o.Name)));
}

Cascade

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

@(Html.Awe().RadioButtonList(new RadioButtonListOpt
{
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 = Db.Meals.Where(o => categories.Contains(o.Category.Id))
.Select(o => new KeyContent(o.Id, o.Name));

return Json(items);
}

Custom Item Render

RadioButtonList/Index.cshtml
@(Html.Awe().RadioButtonList(new RadioButtonListOpt
{
Name = "Meals",
Url = Url.Action("GetMealsImgByCateg", "Data"),
ItemFunc = "site.imgItem"
}
.Parameter("categories", Db.Categories[0].Id)))



Comments