Reload dropdownlist and change selected value

Hi,

On my view I have a dropdownlist that gets its data from the database via the controller.
I also have a form that will add new data to the database table where the dropdownlist data resides.

After the form is submitted and the data is saved in the database, I want to refresh the dropdownlist data and also at the same time, ensure that the newly added record (submitted through the form) is selected on the dropdownlist.

If this is possible, can someone please provide me with a sample?

1 Reply 1 reply marked as answer

BC Berly Christopher Syncfusion Team May 6, 2021 11:43 AM UTC

Hi Eddie Willcox, 
  
Greetings from Syncfusion support. 
  
While using the FOR control with DropDownList, in the form POST action the dropdown list control will be re-render. Due to this, the data source and value will be lost in the control. So, in the form POST action, we need to assign the data source and pass the model to the component to achieve the requested requirement.  
  
Kindly refer the below code example. 
  
  [HttpPost] 
        public ActionResult Index(MaritalStatsvalue model) 
        { 
            ViewBag.data = new MaritalStatsvalue().MaritalList(); 
            return View(model); 
        } 
 
 
  
For your reference, we have prepared the sample and attached it below. 
  
  
  
  
Regards, 
Berly B.C 


Marked as answer
Loader.
Up arrow icon