RadioButtonList

Basic usage

RadioButtonList can get data from an Url, the Url must return a collection of `KeyContent` (or something that inherits from it).
Data can be obtained from an url (via ajax), or be passed directly and rendered on server side with the page.
We could also set `DataFunc` to point to a js function that will return the data, that function can return the data directly or a Promise.
RadioButtonList/Index.cshtml
@(Html.Awe().RadioButtonList(new RadioButtonListOpt
{
Url = Url.Action("GetCategories", "Data"),
Value = Db.Categories[1].Id
}))

@(Html.Awe().RadioButtonList(new RadioButtonListOpt
{
Data = Db.Chefs.Take(5).Select(o => new KeyContent(o.Id, o.FullName)),
Value = Db.Chefs[2].Id
}))
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
{
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