Search code examples
c#asp.netcomboboxsyncfusion

Re-populate syncfusion combobox when navigating to previous page


I have an issue. I have a combobox in syncfusion. The combobox is populated with values. When I select a value and navigate to another page, then come back to the previous page, the selected item that I have selected in the combobox does not appear.

I have stored the selected item in a session.

@Html.EJ().DropDownList("selectCars").Datasource((IEnumerable<object>) 
ViewBag.datasourcex).DropDownListFields(df => df.ID("CarId").Text("CarsFile").Value("CarsFile")).
WatermarkText(Cars.Resources.Resource.SwitchCar).CssClass("headerTextRed").Wid

The session is defined as follows:

  var carsSessions = new CarsSessions();
  // some attributes defined in the session.. 
  carsSessions.ClientKey = decryptedClientKey;
  carsSessions.Language = langueinit;
  carsSessions.DossierIdFile = string.Empty;

The question is how can I populate the syncfusion combobox with the selected item that I have selected before when I navigate to the previous page ?


Solution

  • We suggest you to set enablePersistance property of DropDownList to true, so that the selected items will be maintained in dropdownlist even after navigation of pages. Please refer to the below code

      @Html.EJ().DropDownList("selectCars")
      .Datasource((IEnumerable<object>)ViewBag.datasourcex)
      .Width("250px").DropDownListFields(df => 
       df.ID("CarId").Text("CarsFile").Value("CarsFile"))
      .WatermarkText("Select a Car")
      .CssClass("headerTextRed").EnablePersistence(true)
    
    
     @Html.ActionLink("Navigate to Index Page", "Index", "Home")
    

    We have prepared a sample for your reference which can be downloaded from this link

    Also, refer to the UG for more details