Lookup
It can be declared using the Lookup or LookupFor helper like this:
@Html.Awe().LookupFor(o => o.Meal)
@Html.Awe().Lookup("Category")
It requires a controller to get it's data from, this controller must have 2 actions GetItem and Search, example:
public class MealLookupController : Controller
{
public ActionResult GetItem(int? v)
{
var o = Db.Meals.SingleOrDefault(f => f.Id == v) ?? new Meal();
return Json(new KeyContent(o.Id, o.Name));
}
public ActionResult Search(string search, int page)
{
search = (search ?? "").ToLower().Trim();
var list = Db.Meals.Where(f => f.Name.ToLower().Contains(search));
return Json(new AjaxListResult
{
Items = list.Skip((page-1) * 7).Take(7).Select(o => new KeyContent(o.Id, o.Name)),
More = list.Count() > page * 7
});
}
}
- GetItem is used to display the selected value
- Search is used when the user opens the Lookup's popup and searches for items
Pagination, Custom Item Layout and Table Layout
It has all these features just like the AjaxList (note that Search action returns Json(AjaxListResult))