Autocomplete
It can be declared using the Autocomplete or AutocompleteFor helper like this:@Html.Awe().AutocompleteFor(o => o.Meals)It requires a controller to get it's data from, this controller must have an action GetItems which will receive a "v" parameter with the current value, example:
@Html.Awe().Autocomplete("Categories")
public class CategoryAutocompleteController : ControllerBesides text values the Autocomplete can store the Id of the selected item ( if it was selected from the autocomplete list). To make it do so you can specify the .PropId(name) or you can set .GeneratePropId(true) and it will generate a hidden field with the same name as the current component + "Id".
{
public ActionResult GetItems(string v)
{
v = (v ?? "").ToLower().Trim();
return Json(Db.Categories.Where(o => o.Name.ToLower().Contains(v))
.Select(o => new KeyContent(o.Id, o.Name, false)));
}
}
Comments