Lookup control demo

 

Lookup needs a controller or urls to be specified, by default convention the lookup will look for a controller with the same name as it + "LookupController"

  • action GetItem - used to show the value in the readonly field, it will receive a v parameter which is going to be the key of the selected item
  • action Search - gets data for the search result in it's popup, it should return a Json(AjaxListResult), so it has same features as the AjaxList (table layout, custom item template)

Lookup with custom search 

 
Custom search is achieved by setting .CustomSearch(true) and adding a SearchForm action in the Lookup controller which will render the custom SearchForm view

Lookup Grid 

 
 

Lookup with grid inside the popup, done using the lookupgrid mod that also uses PopupUrl extension.

Lookup with Custom Items template 

 

The Search action of the LookupController returns json of AjaxListResult, we need to set the string AjaxListResult.Content instead of Items in order to achieve Custom Item Template, exactly the same as for the AjaxList helper.

Lookup bound to parents 

Parent Categories:
  •  
Parent Category:
Child Meal:
 

Binding to parents and setting predefined parameters is done the same as for the AjaxDropdown using .Parent() and .Parameter(), values are passed to both GetItem and Search actions.
Unlike other controls the Lookup won't change its value when the value of the parent is changed.

Predefinded parameters 

Meal1 (categories = {Fruits, Legumes}):
 

Besides getting value from parent controls we can also set parameters with predefined values.
A js function can also be set to set parameters for the lookup on each load.




Comments