get the selected item from a DropDownListFor

0

I have the following html code that displays a list of elements.

            <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12">Product</label>
                <div class="col-md-9 col-sm-9 col-xs-12">
                    @Html.DropDownListFor(x => x.CustomerId, Model.ProductsList, new { @data_placeholder = "Select Product...", @data_parsley_required = "true" })
                </div>
            </div>

I need in javascript to obtain the selected element, to pass this parameter through an ajax call to a controller.

How is the id of the selected element obtained? Greetings

    
asked by Luis Gabriel Fabres 26.09.2017 в 00:34
source

1 answer

0

You need to create a kind of controller which only returns the id and the name of what you want to show. With that you fill your dropdawnList and then you get it in the method on selecteditemchanged if you are in C # codebehind or if it is through jquery with the following $ ('# id'). value (); Good luck

    
answered by 26.09.2017 / 01:58
source