State Persistence in EJ 1 ASP.NET MVC AutoComplete
5 Jan 2018 / 1 minute to read
AutoComplete widget can store the model value in the browser’s cookies. Every time after initial rendering, the control gets the model from the cookie only. Using EnablePersistence property you can store the model value in cookies. So when any changes are made dynamically, the values are updated in the cookie. On refreshing the page, the previous state of the AutoComplete control is maintained in the cookie and the control is rendered from it.
Configure state persistence of AutoComplete
The following steps explain you how to enable state maintenance for AutoComplete.
- In the View page, define the AutoComplete control and configure state persistence by using EnablePersistence property.
@*Refer to the DataSource defined in Local Data binding Step 1 *@ @Html.EJ().Autocomplete("autocomplete") .Datasource((IEnumerable<CarsList>)ViewBag.datasource) .AutocompleteFields(field => field.Key("UniqueKey").Text("Text").GroupBy("Category")) .EnablePersistence(true)
The following image is the output for AutoComplete when EnablePersistence is set to ‘true’.
1. Autocomplete during value selection
2. Autocomplete after page refresh