If you need a Select2Dropdown box to not include all the records at once and only load records based on what was typed in. Note that the entire set of records is too long and made the dropdown box slower.
1. Add an usual text field:
<%=new Forms.TextField("ProductCode", Model.SearchCriteria.ProductCode,true){placeholder = "-- Please enter --"}%>
2. The Javascript code (must include the jquery-ui file):
3. Example of the function to set the url dynamically
4. On the server side we need to create a JSON list based on the following Model object:
5. Send back a JSON object data containing the results (the list of the object) in response to the AJAX request.
Result:
Example JSON returned from the controller is like this:
{"results": [{"id": "123","text": "XP3 OIL (123)"}, {"id": "456","text": "SYNTHETIC OIL (456)"}, {"id": "789","text": "XP4 OIL (789)"}]}
Leave a Comment
Comments