MultiLookup
The MultiLookup is similar to theLookuphelper 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
Searchand
Selectedactions will get the
selectedparameter which in case of
Searchaction will be used to exclude the selected items from the search result, and in case of
Selectedaction will be used to get the selected items, example:
public class CategoriesMultiLookupController : ControllerFor custom search have a look at the Lookup helper
{
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))
});
}
}
Comments