Lookup

Declaration:
<% Meal1.Lookup().Controller("MealLookup"); %>
<awe:Ocon runat="server" ID="Meal1" />

Data binding

By default the lookup will get its data from the controller with the same name as it +
LookupController
, but you can specify the controller using
.Controller
extension. The lookup controller must have 2 actions:
GetItem
- display the selected value.
Search
- get the result in lookup popup. Instead of specifying a controller 2 urls can be specified using extensions
.GetItemUrl(str)
and
.SearchUrl(str)
. Example of a lookup controller:
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
        });
    }
}



By accessing this site, you agree to store cookies on your device and disclose information in accordance with our cookie policy and privacy policy .