Lookup


Pick a meal :
 

Lookup needs a controller or urls to be specified, by default convention the lookup will look for a controller with the same name as it + "LookupController"

  • action GetItem - used to show the value in the readonly field, it will receive a v parameter which is going to be the key of the selected item
  • action Search - gets data for the search result in it's popup, it should return a Json(AjaxListResult), so it has same features as the AjaxList (table layout, custom item template)
LookupDemo/IndexContent.cshtml
@(Html.Awe().LookupFor(o => o.Meal)
.ClearButton(Model.ClearButton)
.HighlightChange(Model.HighlightChange)
.Height(Model.Height)
.Width(Model.Width)
.Fullscreen(Model.Fullscreen))
Awesome/Lookup/MealLookupController.cs
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)
{
const int PageSize = 7;
search = (search ?? "").ToLower().Trim();

var list = Db.Meals.Where(o => o.Name.ToLower().Contains(search));

return Json(new AjaxListResult
{
Items = list.Skip((page - 1) * PageSize).Take(PageSize).Select(o => new KeyContent(o.Id, o.Name)),
More = list.Count() > page * PageSize
});
}
}