MultiLookup

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

Data binding

It needs a controller to get data from, the controller must have 3 actions:
GetItems
- display the selected values
Search
- popup search
Selected
- popup selected items Instead of specifying a controller 3 urls can be specified using extensions
.GetItemsUrl(str)
,
.SearchUrl(str)
,
.SelectedUrl(str)
. Both the
Search
and
Selected
actions will get the
selected
parameter which in case of
Search
action will be used to exclude the selected items from the search result, and in case of
Selected
action will be used to get the selected items, example:
public class MealsMultiLookupController : Controller
{
    public ActionResult GetItems(int[] v)
    {
        var items = new List<Meal>();
        if (v != null)
        {
            items.AddRange(v.Select(Db.Get<Meal>));
        }

        return Json(items.Select(meal => new KeyContent(meal.Id, meal.Name)));
    }

    public ActionResult Search(string search, int[] selected, int page)
    {
        const int pageSize = 10;
        selected = selected ?? new int[] { };
        search = (search ?? "").ToLower().Trim();

        var items = Db.Meals.Where(o => o.Name.ToLower().Contains(search) && !selected.Contains(o.Id));

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

    public ActionResult Selected(int[] selected)
    {
        var items = new List<Meal>();
        if (selected != null)
        {
            items.AddRange(selected.Select(Db.Get<Meal>));
        }
        
        return Json(new AjaxListResult
                        {
                            Items = items.Select(o => new KeyContent(o.Id, o.Name))
                        });
    }
}



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