<div mvc-lookup-for="Id" url="People" name="Person" add-handler="true"></div>
public class HomeController : Controller
{
private DbContext Context { get; }
private PeopleRepository Repository { get; }
public HomeController(DbContext context, PeopleRepository repository)
{
Context = context;
Repository = repository;
}
[HttpGet]
public ViewResult Employ()
{
return View();
}
[HttpPost]
public ActionResult Employ(Int32? id, String person)
{
if (id == null)
id = Repository.CreateMissing(person);
Repository.Employ(id);
return RedirectToAction("Index");
}
[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>();
}
}
// Triggered when add new handler is enabled and user selects add new row.
lookup.addEventListener("lookupadd", e => {
e.detail.lookup - lookup's instance.
// Open creation modal instead of posting values.
});