MultiLookup Custom Search

Meals:
  •  

Custom search is achieved by setting .CustomSearch(true) and adding a SearchForm action in the Lookup's controller which will render the custom SearchForm view
MultiLookupDemo/CustomSearch.cshtml
@(Html.Awe().MultiLookup("MealsCustomSearch")
.CustomSearch(true))
Awesome/MultiLookup/MealsCustomSearchMultiLookupController.cs
public class MealsCustomSearchMultiLookupController : Controller
{
//when CustomSearch(true) this action will be rendered instead of the default search
public ActionResult SearchForm()
{
return PartialView();
}

public ActionResult GetItems(IEnumerable<int> v)
{
return Json(Db.Meals.Where(o => v != null && v.Contains(o.Id))
.Select(f => new KeyContent(f.Id, f.Name)));
}

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

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

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)
{
selected = selected ?? new int[] { };
return Json(new AjaxListResult
{
Items = Db.Meals.Where(o => selected.Contains(o.Id))
.Select(o => new KeyContent(o.Id, o.Name))
});
}
}
MealsCustomSearchMultiLookup/SearchForm.cshtml
@using AwesomeMvcDemo.Models
@{ Layout = null; }
@Html.Awe().TextBox("Search").CssClass("awe-searchtxt").Placeholder("search").HtmlAttributes(new{ style="min-width:150px;"})
@(Html.Awe().AjaxRadioList("Categories")
.Url(Url.Action("GetCategories", "Data"))
.Value(Db.Categories.First().Id)
.Prefix("MealLookup")
.Odropdown())