MultiLookup

The MultiLookup is similar to the
Lookup
helper except it is used to select many items instead of one. It can be declared like this:
@Html.Awe().MultiLookupFor(o => o.Meal)
@Html.Awe().MultiLookup("Meal1").Controller("MealLookup")

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 these 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 CategoriesMultiLookupController : Controller
{
    public ActionResult GetItems(int[] v)
    {
        return Json(Db.Categories.Where(o => v != null && v.Contains(o.Id))
                        .Select(f => new KeyContent(f.Id, f.Name)));
    }

    public ActionResult Search(string search, int[] selected)
    {
        return Json(new AjaxListResult
        {
            Items = Db.Categories.Where(o => o.Name.Contains(search) && (selected == null || !selected.Contains(o.Id)))
                .Select(o => new KeyContent(o.Id, o.Name))
        });
    }

    public ActionResult Selected(int[] selected)
    {
        return Json(new AjaxListResult
                {
                    Items = Db.Categories.Where(o => selected != null && selected.Contains(o.Id))
                        .Select(o => new KeyContent(o.Id, o.Name))
                });
    }
}
For custom search have a look at the Lookup helper



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 .