We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

generic dropdown for mvc get selected value

How I can get value using javascript and server side for selected generic dropdown. I have no problem to get the selected text.

3 Replies

VR Varalakshmi R.S Syncfusion Team April 22, 2013 11:07 AM UTC

Hi helmishariff,

 

Thanks for contacting Syncfusion forums.

 

You can get the selected value of the GDD via script in the ClientSideOnClick event. “args._text “ returns currently selected items text. To retrieve the currently selected items text in serverside, first append the text to textbox and then access it in the action using its controls id. Please refer the below given code snippet to achieve this,

<code>

[Script]

function ClientSideOnClick(sender, args) {

        var text = args._text;//return selected text

    }

 

[Controller]

[HttpPost]

        public ActionResult Index(string genericdropdownId)

        {

            //genericdropdownId returns text

            return View();

        }

</code>

 

Kindly try the above methods and let us know if you have any other queries.

 

Regards,

Varalakshmi



MA Manish December 4, 2015 05:51 AM UTC

Hi,

I am unable to get the value from selected DropDownList in JavaScript.

My Snippet:
    function FromCountryChange(sender, args) {  //here both object (sender & args) is null
        $.ajax({
            url: '/PurchaseRequest/GetListOfStates',
            data: { countryCode: 1 },
            error: function (a, b, c) {
                debugger;

            },
            success: function (data1, b, c) {
                debugger;
                $("#FromState").ejDropDownList({
                    dataSource: data1
                });
            }
        });
    }

@Html.EJ().DropDownListFor(model => model.FromCountry).CascadeTo("FromState").WatermarkText("Select From Country").AllowVirtualScrolling(true).VirtualScrollMode(VirtualScrollMode.Normal).DropDownListFields(f => f.Value("Code")).DropDownListFields(f => f.Text("Name")).EnableAnimation(true).EnableIncrementalSearch(true).CaseSensitiveSearch(false).Width("400").ClientSideEvents(evt => evt.Change("FromCountryChange")).Datasource(ViewBag.Countries)


VR Varalakshmi R.S Syncfusion Team December 8, 2015 08:13 AM UTC

Hi Helmishariff,

Thanks for your interest in Syncfusion products.

We are able to retrieve the selected value from change event args “sender”. We have also prepared a simple sample to exhibit this behavior and the sample can be downloaded from the link given below,
http://www.syncfusion.com/downloads/support/forum/108410/ze/Dropdown690932512




You can refer the API reference details from the below given link,
http://help.syncfusion.com/js/api/ejdropdownlist#events:change

Could you please try the sample and if the issue exists still could you please let us the version used in your application? Or please share the application in which this issue was reproduced. We will check the application and update the details to you.

Regards,
Varalakshmi

Loader.
Live Chat Icon For mobile
Up arrow icon