<div mvc-lookup="Ids" url="People" add-handler="true" value="new[] { 2, 4 }"></div>
public class HomeController : Controller
{
private DbContext Context { get; }
public HomeController(DbContext context)
{
Context = context;
}
[HttpGet]
public JsonResult People(LookupFilter filter)
{
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>();
}
}
const lookup = document.querySelector(".mvc-lookup");
// Triggered when selection happens.
lookup.addEventListener("lookupselect", e => {
e.detail.data - selected data array.
e.detail.lookup - lookup's instance.
e.detail.triggerChanges - a boolean specifying if input change events are triggered.
// Preventing default stops lookup data fill.
});
// Triggered when add new handler is enabled and user selects add new row.
lookup.addEventListener("lookupadd", e => {
e.detail.lookup - lookup's instance.
});
const filter = document.querySelector("#FilterId");
// Triggered on lookup additional filter change.
filter.addEventListener("filterchange", e => {
e.detail.lookup - lookup's instance.
// Preventing default stops lookup filter check.
});