AjaxRadioList

It display a list of radiobuttons, and has mods (
Odropodown
,
ButtonGroup
, .. ) that can change its default behaviour:
@Html.Awe().AjaxRadioList("Category")
@Html.Awe().AjaxRadioListFor(o => o.Meal).Url(Url.Action("Data", "GetMeals"))

Data binding

By default it will look for a controller with the same name as it + "AjaxRadioList" and that controller must have a
GetItems
action, but you can also specify
.Url(str)
, the same
url
can be reused by the
AjaxDropdown
and
AjaxCheckboxList
because they all return a collection of
KeyContent
. example of AjaxRadioList controller:
public class CategoryAjaxRadioListController : Controller
{
    public ActionResult GetItems()
    {
        return Json(Db.Categories.Select(o => new KeyContent(o.Id, o.Name)));
    }
}

Client side data binding

A javascript function can be used to set data instead of the url, it is set using
.DataFunc(str)
extension, and when specified
.Url
will be ignored. The js function will receive the same parameters as the controller action, and must also return collection of
KeyContent
. example:
<script>
    var meals = @MyUtils.JsonEncode(Db.Meals.Select(o => new KeyContent(o.Id, o.Name)))
    function getMealsData(){
        return meals;
    }
</script>
@Html.Awe().AjaxRadioList("Meals1").DataFunc("getMealsData")
Parameters will be in form of name-value pair, and to get them as an object you can use
aweUtils.serializeObj
:
function getMealsData(params) {
    var pobj = aweUtils.serializeObj(params);

Binding to parents / Cascading

The AjaxRadioList (like most of the awesome helpers) can be bound to parents using the
.Parent(name, alias="parent", load = true)
extension, when the controls loads, the value of the parent will be sent to the server using the alias as parameter name, and when a parent changes value the child will load (if
load
parameter is true).
Parent Category:
@(Html.Awe().AjaxRadioListFor(o => o.ParentCategory)
           .Url(Url.Action("Data", "GetCategories")))
Child Meal:
@(Html.Awe().AjaxRadioListFor(o => o.ChildMeal)
           .Parent(o => o.ParentCategory)
           .Url(Url.Action("Data", "GetChildMeals")))
The action used to get data for the child control receives the value of the parent which can be used to filter the items:
public ActionResult GetChildMeals(int? parent)
{
    return Json(Db.Meals.Where(o => o.Category.Id == parent).Select(o => new KeyContent(o.Id, o.Name)));
}
you can bind to as many parents as you need, if you have more than one parent with same alias (parameter name), you will get the value as an array:
@Html.Awe().AjaxRadioList("MultiChild").Parent("txt1").Parent("txt2").Parent("txt3","par3")

public ActionResult GetItems(int? v, string[] parent, string par3)
{
    // string[] parent has value of txt1 and txt2
    // par3 has value of txt3
...
}

Parameters

Setting parameters is like setting a parent that never changes its value. example:
@(Html.Awe().AjaxRadioListFor(o => o.Meal)
            .Url(Url.Action("Data", "GetMeals")
            .Parameter("category", 5))
In this example the
GetMeals
action will receive
category
parameter with value = 5.



Comments
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our cookie policy and privacy policy .