jquery - Select2 does not complete the model's value (returns null as property value) -


i use select2 id , name of 1 of properties in model. data source view bag. (it works correctly)

i want set selected value default based on dropdown change. (it works correctly, too)

but after form submit, value of property null

(if select dropdown value clicking works well)

in controller have:

 viewbag.defaultairport = defualtairport.value; // example: "1"   

and in view have:

 <select id="destination" name="destination" class="select2" style="width: 100%; padding: 3px;">                             @foreach (var airport in (list<selectlistitem>) viewbag.airports)                             {                                 <option value="@airport.value">                                     @airport.text                                 </option>                             }                         </select> 

and in scripts:

  function setorgindistination(elementvalue) {     if (elementvalue === "@((int) enums.flightdirection.arrival)") {         $("#destination option[value='@html.raw(viewbag.defaultairport)']").attr('selected', 'selected');   

the selection works because can see in browser, , when use debugging mode in browser option selected.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -