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(mcx.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 = DemoCache.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 = mcx.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", DemoCache.Categories[0].Id)))



Comments