DropdownList
It is declared like this:@(Html.Awe().DropdownList(new DropdownListOpt
{
Name = "AllMealsDd",
Url = Url.Action("GetAllMeals", "Data")
}))
Data
For data the control needs a collection of KeyContent, example:public IActionResult GetAllMeals()
{
var items = mcx.Meals.Select(o => new KeyContent(o.Id, o.Name));
return Json(items);
}
Cascading DropdownList
ASP.net Awesome controls can be bound using theParentextension, this way when the control loads data it will use the parent's value as a parameter (named
parent, unless a different name is specified), and when the parent changes its value, the child will reload. Here's an example:
@(Html.Awe().DropdownList(new DropdownListOptcontroller code:
{
Name = "CatDd",
Url = Url.Action("GetCategories", "Data"),
AutoSelectFirst = true
}))
@(Html.Awe().DropdownList(new DropdownListOpt
{
Name = "MealsDd",
AutoSelectFirst = true,
Url = Url.Action("GetMeals", "Data")
}.Parent("CatDd", "categories")))
public IActionResult GetCategories()
{
return Json(Db.Categories.Select(o => new KeyContent(o.Id, o.Name)));
}
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);
}
DropdownListOpt
DropdownList optionsAutoSearch | Turn autosearch on (with min items = 0) or off |
AutoSelectFirst | Auto select first item |
Caption | Caption when no item is selected |
CaptionFunc | JS func used to render the caption (selected value) |
ClearBtn | Clear button |
CollapseNodes | Make tree nodes collapsible |
CssClass | Css class |
DataFunc | JS function to get data from; when set url is ignored |
Enabled | Enabled |
Favs | Fav buttons |
FieldAttr | Html attributes for the field element |
InLabel | Label text in front of the caption/selected item text |
InputAttr | Html attributes for the input element |
ItemFunc | JS func used to render the selectable items |
Load | Autoload on document ready (default true) |
Name | The name of the control, For editors also the name of the form field and the System.Web.Mvc.ViewDataDictionary key that is used to look up the value |
NoSelectClose | Don't close dropdown on item select |
OpenOnHover | Open dropdown on hover |
ParameterFunc | Set the name of a js function which will return parameters to be sent to the server on each load |
Parameters | Additional parameters to send on load |
Parents | When a parent element changes value the child will reload and get the parent value as a parameter |
PopupMaxHeight | Max popup height |
PopupMaxWidth | Max popup width |
PopupMinWidth | Min popup width |
Prefix | Set Prefix for the html id (use to achieve unique ids for elements with same name) |
SearchFunc | Search func options |
Submenu | Render tree data as submenus |
Url | Url to get data from |
Value | The value of the element. If this value is null, the value of the element is retrieved from the System.Web.Mvc.ViewDataDictionary object. If no value exists there, the value is retrieved from the System.Web.Mvc.ModelStateDictionary object. |
Comments