<input name="Income" /> <div mvc-lookup-for="Id" url="People" filters="Income"></div>
public class HomeController : Controller
{
private DbContext Context { get; }
public HomeController(DbContext context)
{
Context = context;
}
[HttpGet]
public JsonResult People(LookupFilter filter, Int32? income)
{
// Model property names are filtered automatically for not null values.
filter.AdditionalFilters[nameof(Person.Income)] = income;
// Custom names should be filtered by overriding `FilterByAdditionalFilters` method.
filter.AdditionalFilters["IsWorking"] = true;
return Json(new PeopleLookup(Context) { Filter = filter }.GetData());
}
}
public class PeopleLookup : ALookup<Person>
{
private DbContext Context { get; }
public PeopleLookup(DbContext context)
{
Context = context;
FilterCase = LookupFilterCase.Lower;
}
public override IQueryable<Person> GetModels()
{
return Context.Set<Person>();
}
public override IQueryable<Person> FilterByAdditionalFilters(IQueryable<Person> models)
{
if (Filter.AdditionalFilters.ContainsKey("IsWorking") && (Boolean?)Filter.AdditionalFilters["IsWorking"] == true)
models = models.Where(model => model.Income > 0);
return base.FilterByAdditionalFilters(models);
}
}