How to get selected value of dropdown in another page in another dropdown

 I am selecting some values from the dropdown list of one html page. The values of selected items are to be passed into another page with the same drop down list and the items whose values are passed need to be selected automatically. Tried to do it via enable persistence but it didn't work. Below are some screenshots of the same.

Attachment: Screenshots_bc1e6d88.rar

3 Replies

PO Prince Oliver Syncfusion Team February 13, 2018 12:11 PM UTC

Hi Shalini,   
  
Thank you for using Syncfusion products.   
  
The EnablePersistance property will maintain selected values only on the same page. To set the same values for the controls across in different page, you need to pass the selected value from one view to another. Kindly refer to the following code.   

[HttpPost] 
public ActionResult Index(string[] selectCar) 
{ 
    string value = string.Join(",", selectCar); ; 
    return RedirectToAction("DropdownlistFeatures", "Dropdownlist", new { ddlVal = value }); 
} 

Access the selected value in the controller and pass the selected value to the other view.   

public ActionResult DropdownlistFeatures(string selectCar) 
{ 
    string q = Request.QueryString["ddlVal"]; 
    ViewBag.value = q; 
    return View(); 
} 

Access the value in the second view and return it to the control using ViewBag data.  

@Html.EJ().DropDownList("selectCar").TargetID("carsList").ShowCheckbox().Width("150px").Value(ViewBag.value) 

We have prepared a simple sample for your requirement, please find the sample at the following location: http://www.syncfusion.com/downloads/support/forum/135882/ze/ddlpassSelected-1000374836 

Regards, 
Prince 



SH Shalini replied to Prince Oliver February 14, 2018 03:46 AM UTC

Hi Shalini,   
  
Thank you for using Syncfusion products.   
  
The EnablePersistance property will maintain selected values only on the same page. To set the same values for the controls across in different page, you need to pass the selected value from one view to another. Kindly refer to the following code.   

[HttpPost] 
public ActionResult Index(string[] selectCar) 
{ 
    string value = string.Join(",", selectCar); ; 
    return RedirectToAction("DropdownlistFeatures", "Dropdownlist", new { ddlVal = value }); 
} 

Access the selected value in the controller and pass the selected value to the other view.   

public ActionResult DropdownlistFeatures(string selectCar) 
{ 
    string q = Request.QueryString["ddlVal"]; 
    ViewBag.value = q; 
    return View(); 
} 

Access the value in the second view and return it to the control using ViewBag data.  

@Html.EJ().DropDownList("selectCar").TargetID("carsList").ShowCheckbox().Width("150px").Value(ViewBag.value) 

We have prepared a simple sample for your requirement, please find the sample at the following location: http://www.syncfusion.com/downloads/support/forum/135882/ze/ddlpassSelected-1000374836 

Regards, 
Prince 


I want to show these in javascript in angularjs form. How to get the values?



PO Prince Oliver Syncfusion Team February 15, 2018 10:50 AM UTC

Hi Shalini,    
 
Thank you for your update. 
 
To show the values in the AngularJS form, you need to retrieve the value from the ViewBag and assign to the angular scope variable. kindly refer to the following code snippet. 
 
<div ng-app="dropdownlistApp" ng-controller="dropdownlistCtrl"> 
    <form novalidate> 
        <input id="dropdown1" ej-dropdownlist e-targetID="carsList" e-value="value" e-showcheckbox=true e-width="width" /> 
    </form> 
</div> 
 
<script> 
    var item = "@ViewBag.value"; // receive the values from ViewBag here 
    angular.module('dropdownlistApp', ['ejangular']).controller('dropdownlistCtrl', function ($scope) { 
        $scope.value = item; 
        $scope.width = "150px"; 
 
    }); 
</script> 

We have updated the sample as per your requirement, please find the sample at the following location: http://www.syncfusion.com/downloads/support/forum/135882/ze/ddlpassSelected-600113985 

Regards, 
Prince 


Loader.
Up arrow icon