Autocomplete

It can be declared using the Autocomplete or AutocompleteFor helper like this:
@Html.Awe().AutocompleteFor(o => o.Meals) 
@Html.Awe().Autocomplete("Categories")
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:
public class CategoryAutocompleteController : Controller
{
    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)));
    }
}
Besides 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".



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 .